Wednesday, September 18, 2013

Sharepoint WS - Copy - Move the file from one server to another

Here's the method
faxObj is just an object if u wan to include for the field information purpose.
EDMSPath is the source
EDMSRPath is the destination

 private static bool MoveEDMSToEDMSR(ISDAFaxDBO faxObj, string EDMSPath, string EDMSRPath, string msg ="")  
     {  
       using (CopyWS.Copy copyService = new CopyWS.Copy())  
       {  
         copyService.Url = CopyURL;  
         copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;  
         copyService.Credentials = new System.Net.NetworkCredential(username, password);  
         CopyWS.FieldInformation fiEDMS = new CopyWS.FieldInformation();  
         CopyWS.FieldInformation[] fi = { fiEDMS };  
         byte[] byteArr;  
         uint getFile = copyService.GetItem(EDMSPath, out fi, out byteArr);  
         string[] destination = { EDMSRPath };  
         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 = "Record Date";  
         fiRecordDate.Type = CopyWS.FieldType.DateTime;  
         fiRecordDate.Value = faxObj.MaturityDate.ToString("yyyy/MM/ddT00:00:00Z");  
         CopyWS.FieldInformation fiSector = new CopyWS.FieldInformation();  
         fiSector.DisplayName = "Sector";  
         fiSector.Type = CopyWS.FieldType.Choice;  
         fiSector.Value = "Fax";  
         CopyWS.FieldInformation[] fis = { fiRecordDate, fiSector };  
         uint copyresult = copyService.CopyIntoItems(EDMSPath, destination, fis, byteArr, out cResultArray);  
         //Array.Resize<CopyWS.FieldInformation>(ref fi, fi.Length + 2);  
         //fi[fi.Length - 2] = fiRecordDate;  
         //fi[fi.Length - 1] = fiSector;  
         //uint copyresult = copyService.CopyIntoItems(EDMSPath, destination, fi, byteArr, out cResultArray);  
         if (copyresult == 0)  
         {  
           int idx = 0;  
           foreach (CopyWS.CopyResult myCopyResult in cResultArray)  
           {  
             string opString = (idx + 1).ToString();  
             if (cResultArray[idx].ErrorMessage == null)  
             {  
               msg += "Copy operation " + opString +  
                 "completed.\r\n" + "Destination: " +  
                 cResultArray[idx].DestinationUrl;  
             }  
             else  
             {  
               msg += "Copy operation " + opString +  
                 " failed.\r\n" + "Error: " +  
                 cResultArray[idx].ErrorMessage + "\r\n" +  
                 "Code: " + cResultArray[idx].ErrorCode;  
             }  
             idx++;  
           }  
           return true;  
         }  
         else  
         {  
           return false;  
         }  
       }  
     }  

No comments: