Uploading files to Sharepoint (WSS 3.0) document library using HTTP PUT

后端 未结 6 649
甜味超标
甜味超标 2020-12-08 17:56

Hi I have the following piece of code to upload a file to Sharepoint. It uses HTTP PUT:

public static string UploadFile(string destUrl, string sourcePath)
           


        
6条回答
  •  时光说笑
    2020-12-08 18:19

    Is there a paticular reason you can't just use the Sharepoint API (eg. SPFolder.Files.Add) to upload the file? As follows:

    http://msdn.microsoft.com/en-us/library/ms454491.aspx

    public void UploadFile(string srcUrl, string destUrl)
    {
        if (! File.Exists(srcUrl))
        {
            throw new ArgumentException(String.Format("{0} does not exist", 
                srcUrl), "srcUrl");
        }
    
        SPWeb site = new SPSite(destUrl).OpenWeb();
    
        FileStream fStream = File.OpenRead(srcUrl);
        byte[] contents = new byte[fStream.Length];
        fStream.Read(contents, 0, (int)fStream.Length);
        fStream.Close(); 
    
        EnsureParentFolder(site, destUrl);
        site.Files.Add(destUrl, contents);
    }
    

提交回复
热议问题