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

后端 未结 6 650
甜味超标
甜味超标 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:03

    Alex, This happened to me too. You probable should create another another lit or document library and upload files into it to test.

    You may want to check the variable "destUri" to see if it points to exactly the expected sharepoint list.

    My situation is I firstly created a document library "Requrements", there is a typo mistake, then i changed the title to "Requirements". You should notice that sharepoint still keeps the URL to this list as http://server:port/Requrements

    This is an exeption. Hopefully it helps.

    0 讨论(0)
  • 2020-12-08 18:12

    Try:

    void StorePlainFile(string target_url, string filename, byte[] file_bytes)
    {
          string url = target_url + "/" + filename;
          System.Net.WebClient client = new System.Net.WebClient();
          client.Credentials = System.Net.CredentialCache.DefaultCredentials;
          client.Headers.Add("Overwrite", "F");
          byte[] response = client.UploadData(url, "PUT", file_bytes);
    }
    
    0 讨论(0)
  • 2020-12-08 18:14

    I haven't solved my problem yet, that's why I'm here, but I know why you're getting this error.

    The error results because you are not setting a hidden, but required, field. In my case, I had no columns, and certainly none that were required. However, there is a versioning field that is in conflict.

    My intent is to 1) upload the document, and 2) set the document's metadata. 1) and 2) occur over separate HTTP calls. Ideally, I want to do this in a single call, but I don't know how to do this.

    To accomplish this, 1) succeeds, so the document appears in the library. Then when I try to update the metadata, that's when I get the 409 error.

    I'm pretty sure that I first need to insert a step in between 1) and 2) which first downloads the document's list (or manifest) which would in theory contain the needed versioning information. All I would need to do is set the metadata fields I need, and send back to the server.

    No, we don't want to use the Sharepoint API because there are no libraries for it in Java. ;-)

    0 讨论(0)
  • 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);
    }
    
    0 讨论(0)
  • 2020-12-08 18:22

    I've had this issue when I was referencing the url of the document library and not the destination file itself.

    i.e. try http://server name/document library name/new file name.doc

    0 讨论(0)
  • 2020-12-08 18:30

    No clue. But why dont you use Remote Procedure Calls (RPC) thats how i usually do it.

    I found this example that might get you started http://geek.hubkey.com/2007/11/upload-file-to-sharepoint-document.html

    0 讨论(0)
提交回复
热议问题