public string UploadDocument(string fileName, byte[] fileContents, string pathFolder)
...{
if (fileContents == null)
...{
return "Null Attachment";
}
try
...{
int iStartIndex = pathFolder.LastIndexOf("/");
string sitePath = pathFolder.Remove(iStartIndex);
string folderName = pathFolder.Substring(iStartIndex + 1);
SPSite site = new SPSite(sitePath);
SPWeb web = site.OpenWeb();
SPFolder folder = web.GetFolder(folderName);
string fileURL = fileName;
folder.Files.Add(fileURL, fileContents);
if (folder.Files[fileURL].CheckedOutBy.Name != "")
...{
folder.Files[fileURL].CheckIn("File Checked In");
}
return "File added successfully!";
}
catch (System.Exception ex)
...{
return ex.Source + ":" + ex.Message;
}
}
本文介绍了一个使用C#实现的SharePoint文档上传方法。该方法通过接收文件名、文件内容及目标文件夹路径作为参数,将文件上传到指定的SharePoint网站。文章详细展示了如何获取目标文件夹、添加文件并进行版本控制。
5091

被折叠的 条评论
为什么被折叠?



