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

穿精又带淫゛_ 提交于 2019-12-08 06:17:18

问题


I have some client side code that uploads an Outlook email to a document library and as long as the path is pointing to the root of the doc library it works just 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 figur out how to upload to an existing folder i.e. "Emails" in the same document library. Not even Google seems to know the answer :-)

Note: I know that I could use something like the Copy web service within SharePoint to move the file to its final destination, but that is more like a workaround.


When will I learn not to work that late into the night :-(

Sorry about that question. Igalse is right, I just needed to add "emails/" to the URL. I could swear that I had tried that, but then again it sure looks like I didn't.


回答1:


With your code I just added /Emails/ to the projectUrl and the upload worked just fine. Have you tried that? Maybe you have permission problem.



来源:https://stackoverflow.com/questions/312807/upload-document-to-specific-folder-in-a-sharepoint-document-library-using-webcli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!