/// <summary> /// Check if this folder exists in Sharepoint /// </summary> /// <param name="destinationSPFolder">The destination SP folder.</param> /// <returns></returns> public bool CheckIfFolderExists(string destinationSPFolder) { using (WSFiles.Files fileProxy = new WSFiles.Files()) { fileProxy.Url = this.BaseSharePointURL + "_vti_bin/files.asmx"; fileProxy.Credentials = this.NetworkCredential; return fileProxy.CheckIfFolderExist(destinationSPFolder); } }
/// <summary> /// Delete the file with specified URL /// </summary> /// <param name="destinationSPFolder">The destination SP folder.</param> /// <param name="fileName">Name of the file.</param> public void DeleteFile(string destinationSPFolder, string fileName) { using (WSFiles.Files fileProxy = new WSFiles.Files()) { fileProxy.Url = this.BaseSharePointURL + "_vti_bin/files.asmx"; fileProxy.Credentials = this.NetworkCredential; string[] result = fileProxy.DeleteFile(destinationSPFolder, fileName); if (result != null && result.Length > 0 && result.FirstOrDefault(entity => entity.Contains("DeleteFile:Successful")) == null) { throw new ApplicationException("File delete failed:" + result.ToString()); } } }
/// <summary> /// Upload file to SharePoint destination folder /// Should last parent folder not exists, then it will be created, else it will fail to upoad /// </summary> /// <param name="destinationSPFolder">The destination SP folder.</param> /// <param name="fileName">Name of the file.</param> /// <param name="fileData">The file data.</param> public void AddFile(string destinationSPFolder, string fileName, byte[] fileData) { // If file size is the big for webservice upload, zip it! if (fileData.Length > 40000000) { MemoryStream compressedResultStream = new MemoryStream(); ZipOutputStream zipStream = new ZipOutputStream(compressedResultStream); zipStream.SetLevel(6); // 0-9, 9 being the highest level of compression ZipEntry newEntry = new ZipEntry(fileName); newEntry.DateTime = DateTime.Now; zipStream.PutNextEntry(newEntry); // Temp stream, for the report stream have closed already MemoryStream tempStream = new MemoryStream(fileData); StreamUtils.Copy(tempStream, zipStream, new byte[4096]); zipStream.CloseEntry(); zipStream.IsStreamOwner = false; // False stops the Close also Closing the underlying stream. zipStream.Close(); fileName = fileName + ".zip"; fileData = compressedResultStream.ToArray(); } using (WSFiles.Files fileProxy = new WSFiles.Files()) { fileProxy.Url = this.BaseSharePointURL + "_vti_bin/files.asmx"; fileProxy.Credentials = this.NetworkCredential; fileProxy.Timeout = 600000; string[] result = fileProxy.UploadFile(destinationSPFolder, fileName, fileData); if (result != null && result.Length > 0 && result.FirstOrDefault(entity => entity.Contains("UploadFile:Successful")) == null) { throw new ApplicationException("File upload failed:" + result.ToString()); } } }