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[]);  


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);                    }                }


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…