Set Physical Target Folder programmatically

Aug 14, 2009 at 7:38 AM

Is there a possibility to set the physical path of the folder, in which the files should be uploaded, for this control dynamicly? I tried to add this functionality but without success.

 

The problem is that you can only upload the files into the subfolder "Upload" of the current Root-Directory of the ASP.NET Website.

If you have a ASP.NET Website hosted on an IIS 6.0-Server and you are uploading files into the Website-Directory of the project the session sometimes will be reseted. And for applications that need a login etc. this is not so good because  we are storing the userdata in the session.

 

So it would make sense to have the ability to set a folderpath outsite of the asp.net website.

 

Greetings

cptoneeye

Coordinator
Aug 14, 2009 at 3:14 PM
You can save the file anywhere you want. In the example there is this line:
string uploadPath = context.Server.MapPath("~/Upload");

which is then passed to:
fileUpload.ProcessRequest(context, uploadPath);

You can set the uploadPath to any path you need. Something to consider is that the user IIS runs under needs write permissions to the folder.

Hope that helps,
Darick



From: [email removed]
To: [email removed]
Date: Thu, 13 Aug 2009 23:39:01 -0700
Subject: Set Physical Target Folder programmatically [SilverlightFileUpld:65557]

From: cptoneeye
Is there a possibility to set the physical path of the folder, in which the files should be uploaded, for this control dynamicly? I tried to add this functionality but without success.

The problem is that you can only upload the files into the subfolder "Upload" of the current Root-Directory of the ASP.NET Website.
If you have a ASP.NET Website hosted on an IIS 6.0-Server and you are uploading files into the Website-Directory of the project the session sometimes will be reseted. And for applications that need a login etc. this is not so good because we are storing the userdata in the session.

So it would make sense to have the ability to set a folderpath outsite of the asp.net website.

Greetings
cptoneeye


Express your personality in color! Preview and select themes for Hotmail®. Try it now.
Aug 17, 2009 at 8:10 AM

hello darick,

thank you for your reply. it worked.

what is the best way to set this path outside of the control? i want to use the MultiFileUploadControl and pass the path as a parameter. I tried some things but i do not really get the path to the FileUpload HttpHandler. I thaught i could add it as a request-variable of the context.Request.

 

i tried to add it to the initParameters. Pass it to the FileUploadControl.xaml and than pass it to FileUpload-Class for each file.

 

// in addFilesButton_Click of FileUploadControl.xaml
//  [...]
upload.targetpath = this.UploadPath;
files.Add(upload);

// in class FileUpload
public void UploadFileEx()
{
            Status = FileUploadStatus.Uploading;
            long temp = FileLength - BytesUploaded;

            UriBuilder ub = new UriBuilder(UploadUrl);
            bool complete = temp <= ChunkSize;
// here ...variable this.targetpath
            ub.Query = string.Format("{3}filename={0}&StartByte={1}&Complete={2}&UploadPath={4}", File.Name, BytesUploaded, complete, string.IsNullOrEmpty(ub.Query) ? "" : ub.Query.Remove(0, 1) + "&", this.targetpath);

            HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ub.Uri);
            webrequest.Method = "POST";
            webrequest.BeginGetRequestStream(new AsyncCallback(WriteCallback), webrequest);
}

 

 

 

Grettings

cptoneeye

 

 

Aug 17, 2009 at 12:04 PM

Hi Darick,

     I have the same problem. I need to dynamicly change the path.

Depending on witch user of my system will upload files, the destination path on the server will change.

Any advise would really be welcome.

Thanks!