How to set upload folder

Sep 3, 2010 at 6:49 PM

I just downloaded verson 2 and its working great.

However, I can't figure out how to dynamically set the upload folder.  For example, I would expect something like this:

var udialog = new HSS.Interlink.UploadFileDialog

udialog.UploadFolder = "foldername\foldername\  ?????

Am I missing something that allows for that?




Sep 3, 2010 at 8:49 PM

Hello, thanks for the questions and feedback.

You specify the upload folder in your file handler on the server side. Meaning when the file is received you choose where to save the file. When storing to a file system, if you review the sample UploadHandler, I've created a helper method to make it easier to use.

string GetFilePath()
    return Path.Combine(this.GetFolder(FileStoreFolder), this.FileName);
If you still have questions let me know and I'd be more than glad to help.
Sep 4, 2010 at 11:57 AM

Thanks for the quick response.

I saw the code that you referenced, but it doesn't totally answer my question.  My goal is to create upload folders dynamically.  To be specific, my users will log into my website and have a certain DealerID and PurchaseOrderNum, both strings.  I would like to create an upload folder with the structure of ...\DealerID\PurchaseOrdernum\. 

So, what is the best way to pass two string arguments from the Silverlight project into the Web project.  That is, what is the best way to pass arguments to the UploadHandler?


Sep 4, 2010 at 12:47 PM
Edited Sep 4, 2010 at 1:08 PM

Got it. The solution is below, but to explain.


The constructor of the UploadFileDialog takes a callback that allows you to specify metadata for each file being uploaded. In this callback you simply return the string that you want to be uploaded with the file. Then on your UploadHandler simply parse out the string and do as you will with it.


I created a new solution based on the quick start and modified to include specifying metadata and then parsing; it worked perfectly. Below are the modification I made.


The SL Callback specified in the Constructor of UploadFileDialog.


using System.Windows;

using System.Windows.Controls;

using HSS.Interlink;


namespace UploadWithMetadata


       public partial class MainPage : UserControl



              string YOUR_DEALER_ID = "24";ß Hardcoded for example purposes 

              string YOUR_PURCHASE_ORDER = "po0012345";ß Hardcoded for example purposes 



              public MainPage()





              private void btnUpload_Click(object sender, RoutedEventArgs e)


                     UploadFileDialog ud = new UploadFileDialog(GetMetadata); ß Specify the callback 

                     ud.MaxFileSizeKB = int.MaxValue;

                     ud.AllowFileOverwrite = true;

                     ud.Background = new System.Windows.Media.SolidColorBrush(SystemColors.ActiveBorderColor);





              // Called for each file being uploaded

              string GetMetadata(UploadFileViewModel file)


                     return YOUR_DEALER_ID + "," + YOUR_PURCHASE_ORDER; ß Here, return your id and po# comma separated 





Then on the UploadHandler since you only want to use the metadata for Folder creation, I’ve modified the GetFilePath helper method from the quick start.


string GetFilePath()



       string[] metadata = this.Metadata.Split(",".ToCharArray());ß Split the id and po# from the Metadata string

       string YOUR_DEALER_ID = metadata[0];

       string YOUR_PURCHASE_ORDER = metadata[1];


       string directory = Path.Combine(fileStoreUri, YOUR_DEALER_ID, YOUR_PURCHASE_ORDER);

       directory = this.GetFolder(directory); ß Get a valid path; this uses the internal GetFolder() but could be whatever


       return Path.Combine(directory, this.FileName);




Sep 4, 2010 at 1:24 PM


That worked perfectly (on my production machine. I'm still dealing with the FileUpload.ashx error on my web server).