I have the following code inside my Event Receiver, to copy a file from a document library named “Templates” to a sub-folder inside our “Shared documents” library
SPDocumentLibrary template = (SPDocumentLibrary)properties.Web.GetList(properties.Web.ServerRelativeUrl + "/OrderTemplates/"); SPDocumentLibrary projectid = (SPDocumentLibrary)properties.Web.GetList(properties.Web.ServerRelativeUrl + "/Shared Documents/"+properties.ListItemId+"/"); SPListItem softemplete = null; foreach (SPListItem i in template.Items) { if (i.Name.ToLower().Contains("pof draft")) { softemplete = i; } } byte[] fileBytes = softemplete.File.OpenBinary(); string destUrl = projectid.RootFolder.Url + "/" + properties.ListItemId + "/Order Final"; SPFile destFile = projectid.RootFolder.Files.Add(destUrl, fileBytes, true);
now the above code will work well, till the last line:-
SPFile destFile = projectid.RootFolder.Files.Add(destUrl, fileBytes, true);
which will raise an exception as follow:-
The URL 'Shared Documents/113/Order Final' is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web.
although the URL Shared Documents/113/Order Final
should be valid, as i have a folder named 113
and under it there is a sub folder named Order Final
as follow, where the below url is valid:-
http://servername/PM/Shared Documents/113/Order Final
so not sure why i am getting the exception, that the url is not valid??