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)
{
try
{
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.
+1
source to share