public Result CopyItem(ISiteSetting siteSetting, Folder targetFolder, IItem copySource, string newFileName) { SPFolder spFolder = (SPFolder)targetFolder; SPListItem spListItem = (SPListItem)copySource; ISharePointService spService = new SharePointService(); //return spService.CopyFile(siteSetting, spFolder.WebUrl, spFolder.ListName, spFolder.FolderPath + "/" + newFileName, out myCopyResultArray); return(spService.CopyFile(siteSetting, spFolder.WebUrl, copySource.URL, spFolder.GetUrl() + "/" + newFileName)); }
public bool UploadFile(ISiteSetting siteSetting, UploadItem uploadItem, bool saveAsWord, out IItem listItem) { listItem = null; SPFolder spFolder = uploadItem.Folder as SPFolder; string rootFolderPath = spFolder.RootFolderPath; string siteURL = spFolder.SiteUrl; string webURL = spFolder.WebUrl; string destinationFolderUrl = spFolder.GetUrl(); // spFolder.WebUrl.TrimEnd(new char[] { '/' }) + "/" + spFolder.FolderPath.TrimStart(new char[] { '/' }); string listName = spFolder.ListName; byte[] myByteArray = SharePointServiceManager.ReadByteArrayFromFile(uploadItem.FilePath); bool uploadSucceeded = false; string newDestinationUrl = destinationFolderUrl + "/"; string copySource = uploadItem.FilePath; string filename = string.Empty; KeyValuePair <object, object> title = uploadItem.FieldInformations.Where(f => ((Field)f.Key).Name == "Title").FirstOrDefault(); if (title.Value != null) { filename = title.Value.ToString() + new FileInfo(copySource).Extension; } else { filename = new FileInfo(copySource).Name; } string[] copyDest = new string[1] { destinationFolderUrl + "/" + filename }; byte[] itemByteArray = SharePointServiceManager.ReadByteArrayFromFile(uploadItem.FilePath); SPListItem spListItem; string newFileName = copySource; #region Conflicts /* This should be done before this function is called * IOutlookConnector connector = OutlookConnector.GetConnector(uploadItem.Folder.SiteSetting); * bool doThisForNextConflicts = false; * if ((doThisForNextConflicts == true && lastFileExistDialogResults == FileExistDialogResults.Skip) || lastFileExistDialogResults == FileExistDialogResults.Cancel) * { * uploadItem.SharePointListViewControl.DeleteUploadItemInvoke(uploadItem.UniqueID); * return; * } * * bool isCurrentFileUploadCanceled = false; * if ((doThisForNextConflicts == false) || (doThisForNextConflicts == true && lastFileExistDialogResults == FileExistDialogResults.Copy)) * { * while (connector.CheckFileExistency(uploadItem.Folder, null, newFileName) == true) * { * FileExistConfirmationForm fileExistConfirmationForm = new FileExistConfirmationForm(copyDest[0]); * fileExistConfirmationForm.ShowDialog(); * lastFileExistDialogResults = fileExistConfirmationForm.FileExistDialogResult; * doThisForNextConflicts = fileExistConfirmationForm.DoThisForNextConflicts; * * newFileName = fileExistConfirmationForm.NewFileName; * if (lastFileExistDialogResults == FileExistDialogResults.Skip || lastFileExistDialogResults == FileExistDialogResults.Cancel) * { * uploadItem.SharePointListViewControl.DeleteUploadItemInvoke(uploadItem.UniqueID); * isCurrentFileUploadCanceled = true; * break; * } * if (lastFileExistDialogResults == FileExistDialogResults.CopyAndReplace) * { * break; * } * string newCopyDest = copyDest[0].Substring(0, copyDest[0].LastIndexOf("/")) + "/" + newFileName; * copyDest = new string[] { newCopyDest }; * } * } * if (isCurrentFileUploadCanceled == true) * return; */ #endregion Conflicts if (spFolder.IsDocumentLibrary) { uint?result = SharePointService.UploadFile(siteSetting, listName, rootFolderPath, siteURL, webURL, copySource, copyDest, myByteArray, uploadItem.FieldInformations, uploadItem.ContentType, out spListItem); #region NotifyUploadItemInvoke /* This should be done before this function is called * if (uploadItem.SharePointListViewControl != null && listItem != null) * { * uploadItem.SharePointListViewControl.NotifyUploadItemInvoke(uploadItem.UniqueID, listItem); * } */ #endregion NotifyUploadItemInvoke if (result.HasValue && spListItem != null) { uploadSucceeded = true; } } else { int?result = SharePointService.UploadListItemWithAttachment(siteSetting, listName, rootFolderPath, uploadItem, webURL); uploadSucceeded = result.HasValue; } #region UploadFalied / UploadSucceeded callback /* This should be done before this function is called * if (!uploadSucceeded && UploadFailed != null) //why is UploadFailed null sometimes? JJ * UploadFailed(this, new EventArgs()); * else if (UploadSucceeded != null) * UploadSucceeded(this, new EventArgs()); */ #endregion UploadFalied / UploadSucceeded callback return(uploadSucceeded); }
public bool CheckItemCanBeCopied(ISiteSetting siteSetting, Folder targetFolder, IItem copyItem, string fileName) { SPFolder spFolder = (SPFolder)targetFolder; // list item does not anything unique like document has unique file name if (copyItem as SPListItem == null) { return(true); } //SPDocument spDocument = (SPDocument)copyItem; ISharePointService spService = new SharePointService(); return(!spService.CheckFileExistency(siteSetting, spFolder.WebUrl, spFolder.ListName, spFolder.GetUrl(), null, fileName));//JD spFolder.FolderPath }