Break the Data Links in an Excel Workbook

Use this function to break the data links in an Excel workbook. It shows a message asking the user to confirm to break. private void BreakDataLinks(Excel._Workbook wb){ if (DialogResult.Yes == MessageBox.Show(this,”Do you want to break the links to Data Sources ?”, “Links”, MessageBoxButtons.YesNo)) { Array links = (Array)wb.LinkSources(Excel.XlLink.xlExcelLinks); if (links

Retrieve the List of Parameters of a Stored Procedure

The SQLCommandBuilder has the helpful DeriveParameters command that gives you the list of parameters of a stored procedure. All you have to do is: Set the commandText of the command object to the StoredProcedure Name Set the CommandType of the command object to “StoredProcedure” Use the SqlCommandBuilder’s DeriveParameters command to

Command Windows Tricks in the Visual Studio IDE

The Command Window (Ctrl+Alt+A) in the VS.NET IDE has many more features than it appears to have. It is mainly used as the interactive debug window but also you can do many more things with it. Read on to know more about it. You can Create Aliases for commands that

Encrypt a Config Section Using .NET’s Configuration Providers

var configFilePath = @”C:CodeClassifiedConfigurationsapp.config”;var sectionName = “appSettings”;EncryptConfigSection(configFilePath, sectionName);private void EncryptConfigSection(string configFilePath, string sectionName){ var configurationFileMap = new ExeConfigurationFileMap { ExeConfigFilename = configFilePath }; var configuration = ConfigurationManager.OpenMappedExeConfiguration(configurationFileMap, ConfigurationUserLevel.None); var configSection = configuration.GetSection(sectionName); var configurationProvider = new RsaProtectedConfigurationProvider(); if (!configSection.SectionInformation.IsLocked) { configSection.SectionInformation.ProtectSection(configurationProvider.CspProviderName); } configuration.Save();}

Encrypting and Decrypting a Database Connection String

You can encrypt your connection string to a database. Let me rephrase that: you should encrypt data connections. Here is an example of encrypting a connection string and decryprting a connection string. Create the Connection String in your App.Config: connectionString=”Provider=Microsoft.Jet.OLEDB.4.0;Data Source???;DatabaseName;” providerName=”System.Data.OleDb” / Form Code: private void EncryptConnectionString() { System.Configuration.Configuration

Converting JSON Results in Camel Case

Use the CamelCasePropertyNamesContractResolver class of the Newtonsoft.Json assembly to return the JSON serialized string in camel case. var responseObject = employeeProxy.GetAllEmployees();var serializedObjectInCamelCase = JsonConvert.SerializeObject(responseObject, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });

Show Animating Image in a WebBrowser Control During Document Download

A quick way is to use a picturebox and set an animated gif to it. We can make use of the Navigating and Navigated events to show/hide the picturebox as shown below. private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e){ pictureBox1.Visible = true; } private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { pictureBox1.Visible

Quick Way to Escape Special Characters in an XML Document

We can use the SecurityElement’s Escape method of the System.Security namespace to escape all the special characters in an XML file. Code snippet below: string escapedstring = System.Security.SecurityElement.Escape(inputXMLString); …inputXMLString ?contains the XML with special characters.

Create Quick Documentation for your Code in Visual Studio

In order to create quick documentation for your code in Visual Studio, install GhostDoc–a Visual Studio extension that allows you to quickly create XML documentation for Classes, Methods, Properties, Parameters, etc.

No more posts to show