Upload a document to a specific folder in a SharePoint document library using the WebClient

I have client side code that loads an Outlook email into a document library and as long as the path points to the root of the doc library it works fine.

@"https://<server>/sites/<subweb>/<customer>/<teamweb>/<Documents>/" + docname;


is the projectUrl in this function:

public bool SaveMail(string filepath, string projectUrl)
            using (WebClient webclient = new WebClient())
                webclient.UseDefaultCredentials = true;
                webclient.UploadFile(projectUrl, "PUT", filepath);
        catch(Exception ex)
            //TO DO Write the exception to the log file
            return false;
        return true;


but I have not been able to figure out how to upload to an existing folder ie "Email" in the same document library. Even Google doesn't seem to know the answer :-)

Note. I know I could use something like a web copy service in SharePoint to move the file to its final destination, but this seems more like a workaround.

When I learn not to work so late at night: - (

Sorry for this question. Igalse is right, I just needed to add "emails /" to the url. I could swear I tried it, but then again it seems like I didn't.


source to share

1 answer

With your code, I just added / E-mail / to projectUrl and the upload worked just fine. Have you tried this? You may have a permission issue.



All Articles