Wednesday, December 31, 2014

Easy Way to upload a PDF file to SharePoint Document Library

A proven solution to copy a PDF document to SharePoint document library is to use the CopyIntoItems web service. You will never regret your approach if you follow this path.
 
Here are the summary of steps for your coding..
 
1. convert the document into byte for easy transmission
 
                    FileStream fStream = File.OpenRead(fileName);
                    byte[] contents = new byte[fStream.Length];
                    fStream.Read(contents, 0, (int)fStream.Length);
                    fStream.Close();
 
2. Add the web service reference of your SharePoint Server.
 
3. Create a Proxy of your SharePoint service
 
SharePointServerReference.CopySoapClient copy = new SharePointServerReference.CopySoapClient();
 
4. Call the final CopyIntoItems () service
 
uint result = copy.CopyIntoItems(fileName,
                                new string[] { strDestinationUrl },
                                myFieldInfoArray,
                                contents,
                                out myCopyResultArray);
 
where
filename is the name of actual pdf file.
strDestinationUrl  is the location of the document library where file will be uploaded.
myFieldInfoArray can be defined as follows:

                copy.FieldInformation fields = new copy.FieldInformation();
                copy.FieldInformation[] myFieldInfoArray = { fields };

 
 myCopyResultArray can be defined as follows:

copy.CopyResult myCopyResult1 = new copy.CopyResult();
                copy.CopyResult[] myCopyResultArray = { myCopyResult1 };


Please find below url from MSDN for this entire activity for reference :
http://msdn.microsoft.com/en-us/library/copy.copy.copyintoitems(v=office.12).aspx
 

Tuesday, December 30, 2014

Creating GUID from CommandLine

We know that we can create a GUID easily from C# code by just executing Guid.NewGuid() code. This is one of the easiest way. But quite a few times we want GUID for some data manipulation in excel sheet or in Access database. Also many a times we want GUID to be generated in batch programs in that case uuidgen.exe can be a great help.

You can find the uuidgen.exe in the below folder.

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\uuidgen.exe


 

Monday, December 29, 2014

Encrypt Web.Config specific section


A very cool feature of ASPNET_REGIIS tool is to encrypt and decrypt config sections of Web.Config file.

Here is one example for your reference.

encrypt:
aspnet_regiis -pef [sectionName] "D:\inetpub\wwwroot\" -prov DataProtectionConfigurationProvider

decrypt:
aspnet_regiis -pdf [sectionName] "D:\inetpub\wwwroot\" -prov DataProtectionConfigurationProvider

Example :

aspnet_regiis -pef "system.web/identity" D:\inetpub\wwwroot\thresholdui -prov DataProtectionConfigurationProvider