bluetickk bluetickk - 5 days ago 5
ASP.NET (C#) Question

ASPx Dev Express File Upload Control

I want to be able to upload a file onto my server.

I know my code works, I cannot figure out what is going on with the path name though, and how to set it to the websites directory.

Here is my c#

protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
{
string uploadFolder = "~/files/";
string fileName = e.UploadedFile.FileName;

e.UploadedFile.SaveAs(uploadFolder + fileName);
e.CallbackData = fileName;
}


This is the error message I get when trying to upload the file

Could not find a part of the path 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\~\files\project_questionnaire.doc'.


I have tried everything for the uploadFolder... "../files" "files/" "/files/" etc..

Any help would be appreciated!

Answer
protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
        {
                string uploadFolder = Server.MapPath("~/files/");
                string fileName = e.UploadedFile.FileName;

                e.UploadedFile.SaveAs(uploadFolder + fileName);
                e.CallbackData = fileName;
        }

See here for a good guide.

Comments