Have you found yourself wondering if your HTML tags have matching closing tags?
Wouldn’t it be great to have a visual aid to help you read your code and verify that is aligned properly and the tags match?
There is a great Visual Studio extension named Indent Guides which you can download from CodePlex, @ http://visualstudiogallery.msdn.microsoft.com/e792686d-542b-474a-8c55-630980e72c30 once installed, restart Visual Studio and you can easily notice that your source code has now a visual line that you can use to ensure indentation is correct and to match tags. See screenshot below.
Speaking of Visual Studio tips and tricks, here are another couple of tricks to improve the editor experience:
- You can use Ctrl+E, D to format the selected text. This would add indentation to your code so it is easier to read, although you may want to use with caution because the indentation can be excessive for some people. You can find this option on the Edit -> Advanced menu.
- A common question is how to display Line number on the Visual Studio 2010 editor. To do so, go to the Tools menu, click on Options -> Expand Text Editor, select a language, for example C# and click on General if is not selected automatically. Then on the last section of the window named “Display” enable the Line Numbers checkbox.
- What if the code you are reading is all collapsed because somebody else used the Outline feature? Well you can quickly turn off the Outline by pressing Ctrl+M, P, you can find all the Outline options on the Edit menu Outlining
Hope this helps somebody out there,
Will
Thursday, December 1, 2011
Wednesday, November 23, 2011
Clearing Another User's Checkout in TFS
A long gone coworker has left a few objects checked out in TFS, now you discover that you need to clear the checkout in order to incorporate new changes. How can this be done?
Clearing out another user's check out is NOT supported from the GUI, however there is a command line option to accomplish this:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>TF undo /workspace:WorkstationName;UserName $/ProjectName/ObjectName.cs /s:http://YourTFSServer:8080
Once the command completes, refresh the Source Control Explorer to see the changes, you may also need to get the latest version of the project if multiple objects have been locked for a long period of time.
Hope this helps,
Will
CodeProject
Tuesday, November 15, 2011
Using DotNetZip Library to Compress Data in ASP.Net
I recently worked on a project that involved creating encrypted Zip files. Data is captured on a web form and then written to a text file.
At first, the task sounded complex. However, if you are aware of the DotNetZip library existence, your task just got easier.
You can download the DotNetZip library from http://dotnetzip.codeplex.com/
Once you download and install the package, you will need to add a reference to Ionic.Zip.dll or copy the file to your \lib folder, this is all you need to start generating your own zip files.
The best part: DotNetZip is free!!
DotNetZip is well documented and is much easier to use than any other solutions out there including System.IO.Compression and SharpZipLib, after trying both methods I would highly recommend DotNetZip because is incredibly easy to use.
Below is a sample method to illustrate how to easily to compress content that is being passed as a string.
The method takes the file name and the content as arguments:
The method declares a variable of type ZipFile which is available once you add a reference: "using Ionic.Zip;" That declaration creates the shell of the zip file. After that, the process to save the file is simple, add a password if needed, add an encryption method and you can proceed to add an entry to the Zip file by using AddEntry.
Of course, you could add multiple files to the same Zip archive. Finally, you can Save the contents of the Zip which in this case are returned by the method as a MemoryStream that could be used for other purpose such as creating an e-mail attachment.
Be aware that if you need to encrypt the contents of the zip, choosing the encryption method is important because the built-in Windows unzip feature can only decrypt PkZip.Weak content. You would need to have WinZip or WinRar Installed on the target workstation to unzip contents encrypted with the WinZipAes128 or WinZipAes256 methods.
Hope this is helpful and feel free to contact me if you have any questions,
Will
CodeProject
At first, the task sounded complex. However, if you are aware of the DotNetZip library existence, your task just got easier.
You can download the DotNetZip library from http://dotnetzip.codeplex.com/
Once you download and install the package, you will need to add a reference to Ionic.Zip.dll or copy the file to your \lib folder, this is all you need to start generating your own zip files.
The best part: DotNetZip is free!!
DotNetZip is well documented and is much easier to use than any other solutions out there including System.IO.Compression and SharpZipLib, after trying both methods I would highly recommend DotNetZip because is incredibly easy to use.
Below is a sample method to illustrate how to easily to compress content that is being passed as a string.
The method takes the file name and the content as arguments:
internal MemoryStream ZipString(string aZipFileName, string aContents, string aMode)
{
try
{
//Add these to your AppSettings on Web.Config
string sZipFilePassword = ConfigurationManager.AppSettings["ZipFilePassword"];
string sZipFileEncryption = ConfigurationManager.AppSettings["ZipFileStrongEncryption"];
//Stored the zippped data on this memory stream
MemoryStream msZippedContent = new MemoryStream();
// Creating Zip
using (var zip = new ZipFile())
{
// Add the password protection
zip.Password = sZipFilePassword;
if (sZipFileEncryption == "N")
{
//PkZipWeak is not a string encryption method, but is supported by any UnZip utility
zip.Encryption = EncryptionAlgorithm.PkzipWeak;
}
else
{
//WinZipAes128 and WinZipAes256 is NOT compatible with Windows ZIP
zip.Encryption = EncryptionAlgorithm.WinZipAes256;
}
// Add the desired file to the Zip
zip.AddEntry(aZipFileName, aContents, Encoding.ASCII);
// Send the contents of the ZIP back to the output stream
zip.Save(msZippedContent);
return msZippedContent;
}
}
catch (Exception genEx)
{
Response.Write(genEx.Message);
return null;
}
}//ZipString
The method declares a variable of type ZipFile which is available once you add a reference: "using Ionic.Zip;" That declaration creates the shell of the zip file. After that, the process to save the file is simple, add a password if needed, add an encryption method and you can proceed to add an entry to the Zip file by using AddEntry.
Of course, you could add multiple files to the same Zip archive. Finally, you can Save the contents of the Zip which in this case are returned by the method as a MemoryStream that could be used for other purpose such as creating an e-mail attachment.
Be aware that if you need to encrypt the contents of the zip, choosing the encryption method is important because the built-in Windows unzip feature can only decrypt PkZip.Weak content. You would need to have WinZip or WinRar Installed on the target workstation to unzip contents encrypted with the WinZipAes128 or WinZipAes256 methods.
Hope this is helpful and feel free to contact me if you have any questions,
Will
CodeProject
Labels:
.Zip,
ASP.Net,
C#,
CodeProject,
DotNetZip
Location:
Tampa, FL, USA
Saturday, November 12, 2011
Save the directory listing to a text file
Here is a useful and handy trick is to write the contents of a directory listing to a text file so you can create a report or execute a search in another tool, say Word or Excel.
I've used this in the past for other simple stuff for example, creating a spreadsheet out of a massive MP3 directory. Since I have music organized by album, each album being a directory I wanted to write the contents of My Music to a text file.
Go to CMD:
C:\User\My Music>dir *. >>Music.txt
This will list only directories and send the contents to the music.txt file. Of course you must have write permissions in the directory.
If you want a cleaner listing. Say only the directory names without any other information try:
C:\User\My Music>dir *. /b >>Music.txt
Hope it helps,
Will
I've used this in the past for other simple stuff for example, creating a spreadsheet out of a massive MP3 directory. Since I have music organized by album, each album being a directory I wanted to write the contents of My Music to a text file.
Go to CMD:
C:\User\My Music>dir *. >>Music.txt
This will list only directories and send the contents to the music.txt file. Of course you must have write permissions in the directory.
If you want a cleaner listing. Say only the directory names without any other information try:
C:\User\My Music>dir *. /b >>Music.txt
Hope it helps,
Will
How to clear a String Builder?
How to clear a StringBuilder?
By now you probably realized that rhere is no Clear method.
You can use the two lines below, the assumption is that you are going to reuse the StringBuilder several times in your code and you want to temporarily clear it to ensure is empty and ready for a new assignment.
sbSQL.Length = 0;
sbSQL.Capacity = 0;
This trims the contents but also shortens the capacity to zero. I was surprised to noticed that both Length and Capacity properties are writable.
Hope it helps,
Will
CodeProject
By now you probably realized that rhere is no Clear method.
You can use the two lines below, the assumption is that you are going to reuse the StringBuilder several times in your code and you want to temporarily clear it to ensure is empty and ready for a new assignment.
sbSQL.Length = 0;
sbSQL.Capacity = 0;
This trims the contents but also shortens the capacity to zero. I was surprised to noticed that both Length and Capacity properties are writable.
Hope it helps,
Will
CodeProject
Subscribe to:
Posts (Atom)
