1

I'm trying to upload files to a SharePoint 2007 environment using PUT requests. Using the object model isn't an option since my application is not running on one of the SharePoint servers and unfortunately 2007 doesn't have a client model.

I'm using the rather default upload code which is found on many blogs:

    WebRequest request = WebRequest.Create(destinationUrl);

    request.Credentials = credential;
    request.Method = "PUT";

    byte[] buffer = new byte[1024];

    // Write the contents of the local file to the
    // request stream.
    using (Stream stream = request.GetRequestStream())
    using (FileStream fsWorkbook = File.Open(filePath, FileMode.Open, FileAccess.Read))
    {
      int i = fsWorkbook.Read(buffer, 0, buffer.Length);

      while (i > 0)
      {
        stream.Write(buffer, 0, i);
        i = fsWorkbook.Read(buffer, 0, buffer.Length);
      }
    }

This works fine, untill I run into a situation where I need to recursively upload folders with their contents and there are folders with special characters like '+'. Whenever I try to upload a file there, I get a 404 error.

I have tried escaping the + with %2b, I've tried replacing it with a space or an empty character, nothing seems to work.

So I can properly upload to List/folder/, or List/folder/subfolder/, but not to list/folder + name/. Any ideas on a good reliable workaround?

1 Answer 1

0

I switched to the RPC methods for uploading files. Works better and supports setting metadata at the same time. IMHO the better way to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.