C#将文档上传到sharepoint文档库

来源:互联网 发布:快速排序c语言实现 编辑:程序博客网 时间:2024/04/29 00:06

 

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;
            }

        }
原创粉丝点击