I have the following code to add a file inside a folder:-

using (FileStream fs = new FileStream(context.Site.Url + templetefile.File.ServerRelativeUrl, FileMode.Open))
                    FileCreationInformation fci = new FileCreationInformation();
                    fci.Overwrite = false;
                    fci.Url = destUrl;
                    fci.ContentStream = fs;
                    Microsoft.SharePoint.Client.File destFile = shareddocsList.RootFolder.Files.Add(fci);


but i am getting this exception The given path's format is not supported on the FileStream fs = new FileStream(context.Site.Url + templetefile.File.ServerRelativeUrl, FileMode.Open).. although the context.Site.Url + templetefile.File.ServerRelativeUrl will generate a url as follow https://*****.sharepoint.com/OrderManagement/OrderTemplates/Request for Approval.oft.. which is a valid url to a file... so can anyone advice on this error please?


1 Answer 1


From above comments, I see that you want to move files/folders to another folder. If so, you can have a try following easy way:

MoveCopyUtil.MoveFolder method


        string SiteUrl = "https://xxx.sharepoint.com/sites/dest";     

        var pwd = "******";
        var username = "[email protected]";

        var authManager = new AuthenticationManager();
        ClientContext context = authManager.GetSharePointOnlineAuthenticatedContextTenant(SiteUrl, username, pwd);

        string sourceFolder = "https://xxx.sharepoint.com/sites/source/test doc lib/testfolder";
        string destFolder = "https://xxx.sharepoint.com/sites/dest/Shared Documents/testfoldermove";

        MoveCopyUtil.MoveFolder(context, sourceFolder, destFolder,new MoveCopyOptions { 

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.