Nice add-ins for Reflector

Nice add-ins for Reflector:-
 
 
(if you dont have reflector,download the same from http://www.aisto.com/roeder/dotnet).
 
One of the very useful add-in is the "diff" add-in. Which would point out the differences between the two versions of the same assemblies including any added/changed/deleted members/methods.
And also the "File Diassembler" where all you have to do is provide the assembly (with the dependent assemblies) you want to disassemble and it would generate the class library out of the same with all the source code.
Others are code search,Code Metrics and many more.
 
In order to use an add-in in the Reflector :-
a) Copy the all the binaries for the add-in in the same directory as the Reflector.exe.
b) In the reflector,View > Add-In. In the Add-ins dialog,Add the dll for the Add-in.
c) You should see the added "Add-In" under Tools menu.   
 

Use sections in the config file and access them…

(NameValueCollection)ConfigurationManager.GetSection("applicationSettings/ConnectionStrings");

for the following XML fragment in the config file:-
 
<applicationSettings>
<ConnectionStrings>
<add key="DevConnectionstring" value="server=myserver1;database=mydatabase;uid=ashish;pwd=password"/>
<add key="QAConnectionstring" value="server=myserver2;database=mydatabase;uid=ashish;pwd=password"/>
<add key="ProdConnectionstring" value="server=myserver3;database=mydatabase;uid=ashish;pwd=password"/>
</ConnectionStrings>
</applicationSettings>

Visual studio 2005 Build error :- The volume for a file has been externally altered so that the opened file is no longer valid

Just clean the solution and rebuild.
 
Just dont have any idea why the above error happened this morning when I tried to add some code to a windows service and tried to build the solution.But it has a simple resolution,just clean the solution. 🙂  [Solution Explorer > Right click on the Solution> Select "Clean Solution"].
 
 
 

Convert string to byte array and viceversa

                   byte[] elementByteContent= contentObject.Content; //  this  byte array content
                    string elementStringContent = System.Text.Encoding.UTF8.GetString(elementByteContent);
                    elementStringContent = elementStringContent.Replace(" ", "");
                    if (elementStringContent == string.Empty)
                    {
                        elementStringContent = "<P>&nbsp;</P>";
                        contentObject.Content = System.Text.Encoding.UTF8.GetBytes(elementStringContent);
                    }

Removing comments using XPathNavigator.SelectDescendants(System.Xml.XPath.XPathNodeType.Comment,false);

 

#region Remove XML comments
System.Xml.XPath.
XPathNavigator path = xmlDoc.SelectSingleNode("w:document",xmlNSMgr).CreateNavigator();
System.Xml.XPath.
XPathNodeIterator commentsIterator = path.SelectDescendants(System.Xml.XPath.XPathNodeType.Comment,false);
if (commentsIterator.Count > 0)
{
while (commentsIterator.MoveNext())
{commentsIterator.Current.DeleteSelf();}}
#endregion

 

For the following XML:-(We needed to remove "<!–  Generated by Aspose.Words for .NET 4.4.1.0   –> ")

 

  <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
– <w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
– <!–  Generated by Aspose.Words for .NET 4.4.1.0
  –>
– <w:body>
– <w:p>
– <w:r>
– <w:rPr>
  <w:b />
  <w:color w:val="FF0000" />
  <w:sz w:val="24" />
  </w:rPr>
  <w:t>Evaluation Only. Created with Aspose.Words. Copyright 2003-2007 Aspose Pty Ltd.</w:t>
  </w:r>
  </w:p>
  </w:body>
  </w:document>

Process.Start() – Open the file from the application after writing on the file

There are instances where you write to a file (say XML/Text file/word) fo debugging/testing etc.In those scenarios,your program finishes writing to the file and then you open the file manually in the application(IE/Notepad/Microsoft word) to see what the program has written in that file.You can actually launch that application after you finish writing to that file from with in the program making the whole process quick.The file opens in its default application right after you finish debugging without you needing to manually open it.
 

The steps:- (2 lines):-
 
a) Include the namespace:-
using System.Diagnostics;

b) Start the process for the saved file:-
//
//Code to save the file
//
 
// Following line would open the saved file in its default application
Process.Start("SavedFullFilePath");
 
 
Example:-
// Code to save the file
XmlDocument Xdoc = new XmlDocument();
string folderPath = @"C:\Ashish\";
string upload = folderPath + "2007.docx";
string savename = folderPath + "WordPackage.xml";
ZipPackage zipPackage = null;
byte[] packageData = null;
Stream stream;
packageData = GetBytesFromFile(upload);
stream =
new MemoryStream(packageData);
if (stream != null)
zipPackage = GetZipPackageFromStream(stream);
Xdoc = RRD.DSA.SCP.OfficeAssembler.
WordToXyXmlAssembler.ConvertToXyXml(zipPackage);
Xdoc.Save(savename);

// Following line would open the saved file in its default application (Internet explorer)
Process
.Start(strSave);

 
 

can not drop user from database

Problem :-
 
I can not delete user from a database in sql2005 beta 3.
the message errror is :

TITLE: SQL Server Management Studio
—————————————-

Drop failed for User ‘Amministratore’.  (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft SQL Server&ProdVer=9.00.0981.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Drop+User&LinkId=20476

—————————————-
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

—————————————-

The database principal owns a schema and cannot be dropped. (Microsoft SQL Server, Error: 15138)

 

 

 

Solution:-

1) Expand Schemas(should be like a folder under <yourdatabase> -> Security) .
2) Script the the unwanted "userSchema" save it and and then Delete the schema.
3) Then, go back to the User,script the user and then delete the user.

4) Associate the schema back to the user by running the script.