Wednesday, September 18, 2013

Sharepoint WS - Copy - Save local file to EDMS

Here is the method to save the local file in your computer and put it to the document library, my list name is EDMS.

 private static bool saveFileInEDMS(ISDAFaxDBO faxObj, string localPath, string EDMSPath)  
     {  
       using (CopyWS.Copy copyService = new CopyWS.Copy())  
       {  
         copyService.Url = CopyURL;  
         copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;  
         copyService.Credentials = new System.Net.NetworkCredential(username, password);  
         string[] destination = { EDMSPath };  
         CopyWS.CopyResult cResult1 = new CopyWS.CopyResult();  
         CopyWS.CopyResult cResult2 = new CopyWS.CopyResult();  
         CopyWS.CopyResult[] cResultArray = { cResult1, cResult2 };  
         CopyWS.FieldInformation fiRecordDate = new CopyWS.FieldInformation();  
         fiRecordDate.DisplayName = "Date";  
         fiRecordDate.Type = CopyWS.FieldType.DateTime;  
         fiRecordDate.Value = faxObj.MaturityDate.ToString("yyyy/MM/ddT00:00:00Z");  
         CopyWS.FieldInformation[] fis = { fiRecordDate };  
         FileStream strm = new FileStream(localPath, FileMode.Open, FileAccess.Read);  
         Byte[] fileContents = new Byte[strm.Length];  
         int ia = strm.Read(fileContents, 0, Convert.ToInt32(strm.Length));  
         strm.Close();  
         uint copyresult = copyService.CopyIntoItems(localPath, destination, fis, fileContents, out cResultArray);  
         if (copyresult == 0)  
         {  
           return true;  
         }  
         else  
         {  
           return false;  
         }  
       }  
     }  

No comments: