Code Snippets for common operations

1. read all the contents of a File string output = File.ReadAllText(<FilePath>); 2. Write contents to a File File.WriteAllText(<FilePath>,Encoding); 3. Convert String to Byte Array byte[] buf = System.Text.Encoding.<Encoding>.GetBytes(string); 4. Convert Byte to String string output = System.Text.Encoding.<Encoding>.GetString(byte[]);  

2

Creating a new document in a Document Library

 string _siteUrl = “http://localhost”;                 using (SPSite _site = new SPSite(_siteUrl))                {                    using (SPWeb _web = _site.OpenWeb())                    {                        SPFolder _folder = _web.Folders[“<Document Library Name>”];                        _web.AllowUnsafeUpdates = true;                        _folder.Files.Add(“Contoso Final Document + “.” + extension, bytes);                    }                }

1

Calling a WCF service from Infopath

Recently I got into a scenario where I wanted to call a WCF service from within an Infopath Form service, Infopath does not supports configuration files so my service was not able to pick the Binding and Endpoint setting for the Service at the client side To resolve I programmatically created a channel for the…

1

Debugging Web parts in WSS

  Although VS 2005 provides awesome support for developing Web parts one of the pain points can be debugging a web part, some tips on how to debug a web part :   Two methods:   Direct:  Attach debugger to the w3wp.exe process that hosts SharePoint. Automatic: make the url of a given page as…

0

SO Terminology

 Some common confusions (terms :)) with respect to SO Business Process It consists of a sequence of activities that produce a valuable result.     Business Activities Business activities or tasks are the units that when combined form the business process, Cost, revenue, resources, timelines, input and output are all examples of business activities; they are a…

1

Implementing Singleton using .NET Framework

Leveraging the .NET Framework features (sealed class and read-only properties) to implement the Singleton pattern in a thread safe manner.     The Singleton Class     using System; using System.Collections.Generic; using System.Text;     namespace SingletonUsingDotNetFramework { //Create a sealed class so it cannot be derived sealed class Singleton { private Singleton() { }…

0