Last post Nov 15, 2016 12:59 AM by oned_gk
Nov 14, 2016 08:38 PM|rogue1|LINK
I am trying to upload a file using devexpress save as function which works exact same as the standard asp.net uploader but i am getting the following error
> Could not find a part of the path 'C:\Projects\fhs\fhs\Uploads\documents\VX00150\Barry Allen\Aperture - Signature Template.docx'.
string UploadDirectory = WebConfigurationManager.AppSettings["uploadDirectory"].ToString();
Which contains the directory
UploadDirectory refers to a virutal directory setup in the web config which im getting via the property.
<add key="uploadDirectory" value="~\Uploads\" />
protected void UploadControl_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
UploadControl.Enabled = false;
string id = Request.QueryString["Case"];
if (id != null)
CaseId = Guid.Parse(id);
OpenCase = _dal.GetCaseById(Guid.Parse(id));
string PersonId = Session["CurrentPersonalMainID"].ToString();
Personal = _dal.GetPersonalByPersonalId(new Guid(PersonId));
e.CallbackData = SavePostedFile(e.UploadedFile, OpenCase.CaseReference, Personal.firstName, Personal.lastName);
The below saved postedfile is called from above
public string SavePostedFile(UploadedFile uploadedFile,string IVACaseRef, string firstName ,string lastName)
string fileName = uploadedFile.FileName;
FileInfo fileInfo = new FileInfo(uploadedFile.FileName);
string fullFileName = CombinePath(fileName);
string docsPath = UploadDirectory + @"documents\" + IVACaseRef + @"\" + firstName + " " +
lastName + @"\";
string resFileName =docsPath + fileInfo.Name;
bool exists = System.IO.Directory.Exists(resFileName);
attachment = new System.Net.Mail.Attachment(resFileName.ToString());
// we need to reget this as issue with postback and the fileuplaod
FormsIdentity _identity = (FormsIdentity)Context.User.Identity;
_identity = (FormsIdentity)Context.User.Identity;
catch (Exception ex)
string inner = string.Empty;
if (ex.InnerException != null)
inner = ex.InnerException.ToString();
// logger.Error("Error in GetNotificationById function aperturenetdal " + ex.ToString() + " " + inner);
Nov 14, 2016 10:03 PM|Rion Williams|LINK
Just as a question, but are the redundant "fhs" directories correct?
C:\Projects\fhs\fhs\Uploads\documents\VX00150\Barry Allen\Aperture - Signature Template.docx
If so there may be an issue with how you are building the path and might want to consider debugging through it to ensure that's correct.
Nov 14, 2016 10:27 PM|PatriceSc|LINK
It should mean that the leaf directory can't be reached because a folder name along this path is not correct. Double check the full path. For example you really have a fhs folder into another fhs folder rather than just a single fhs folder?
For now I didn't gave a close look but it seems you'll have other issues if you fix this first issue: I see a test on the resFileName "directory" but it includes a file name and if not found you then create another directory (likely the correct one this
time). The attachment seems to use a virtual path rather than a physical path (ie you should use the same Server.MapPath value you used earlier).
For example it might be clearer if you reuse again and again a variable you'll use to build a final value (such as the final physical path) that you'll then use. Here you keep intermediate results even if you won't really need them and then it's easier to
use the wrong variable here or there...
Nov 14, 2016 10:29 PM|rogue1|LINK
Yes are i found the problem though have a look at what im passing to create directory and then the file differnt things
Nov 14, 2016 11:06 PM|PatriceSc|LINK
Not sure what is the current situation? Do you mean that it solved your issue or do you still have this "Could not find a part of the path" error. Ah it seems your directory name is still wrong in the code. So it seems to me you could create a c:\Windows\system32\~\Uploads\documents\VX00150\Barry
Allen directory rather than the expected 'C:\Projects\fhs\fhs\Uploads\documents\VX00150\Barry Allen directory.
Could you please double check that each folder of this path is really existing ? So I would try to simplify by doing something such as :
path=System.IO.Path.Combine(path,@"documents\" + IVACaseRef + @"\" + firstName + " " + lastName);
// At this step we should have the folder, we can create it if needed
if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path);
// At this step we have the full file path
As you see I'm just using a single path variable. I'm building the physical path immediately and then I add the other directory parts, I then create this directory if needed before adding the file name only to the same variable to finally handle the file.
It should allow to avoid the current confusion between multiple variables and virtual vs physical path...
Nov 15, 2016 12:59 AM|oned_gk|LINK
Seem like the problem because you use Server.MapPath() for not exist file
Because the fullpath containt folder and filename, but the filename is not exist. So, you get error message
Use Server.MapPath() to get folder location only, then combine it with filename to upload
Server.MapPath(folderpath) + "\\" + filename
string docsPath = Server.MapPath(UploadDirectory) + @"\documents\" + IVACaseRef + @"\" + firstName + " " + lastName + @"\";
Use Server.MapPath to get uploadDirectory phisical path instead of to get file phisical path