Is there any way to have Save as dialog box in Silverlight?
In my application user can upload the files using RADUPload Control.
Now i need to provide him a way to download the previously uploaded files.
for previewing the files i am using
"System.Windows.Browser.
HtmlPage.Window.Navigate(new Uri(Path));" but unable to provide the save as option for downloading the files.
Please suggest.
Thanks,
Andy...
10 Answers, 1 is accepted
Thank you for the nice suggestion! Unfortunately we currently do not have a Download control.
However, we created a sample application which I hope will suite your scenario. Here is a short description:
- the RadUpload control is used to upload files;
- there is a StackPanel next to the upload control where we append a HyperlinkButton for each successfully uploaded file;
- The browser will take the necessary action for each link depending on the file type.
Please give it a try and let me know if it solves your issue.
Regards,
Ivan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

Hi Ivan,
Thanks for your efforts.
i have tried your solution but the save as option is coming only in case of zip files and other files like (.txt..doc,xls) are getting opened directly.
Please suggest.
Thanks
Andy
At the moment you can try to resolve the "save-as" problem with zipping the uploaded files at the server side. I know this approach is not the best one, but it is the only workable until we find and implement a better solution.
Kind regards,
Ivan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

it should be the pair with upload control, right?
thanks,
Young
We don't have plans for a file download control for the moment, so we can't stick to any specific date. I added your suggestion in our public issue tracking system:
www.telerik.com/support/pits.aspx
Best wishes,
Valentin.Stoychev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

For most content types (.png, .jpg, .txt, .xml) are all support and will show not problem, but I have problem that my users like to be able to save using the RadUpload control and then be able to view excel files, word docs, and outlook email saves (.msg files) and I am wondering if you can pass a request header of the content type (i.e. application/ms.outlook) into the Navigate method? Or can a URI include the content type?
Note: I don't mind if it shows in the browser or pops up a save for the users.
Regards,
Shaun Sharples
I'm not sure that I get your idea. About the Navigate method, you can't pass content type, but you can pass parameters in the query string, that you can use later after navigating to the page.
I'm also not sure why you need RadUpload?
Can you clarify your scenario a little bit more?
Thank you for your cooperation.
Miro Miroslavov
the Telerik team

Hey Miro,
Thanks for the response. Here is my scenario:
I have a Silverlight ChildWindow, which contains an OK and Cancel button, a RadUpload control, and a list box control. The list box will contain all the files which have been uploaded for the currently selected customer.
I currently have a selected customer with which I want to be able to upload a file to a folder on the server (the kind of files I would like the user to be able to upload are emails, images and documents) and then assign the uploaded files to that customer by means of creating a database entry linking the Customer ID to the File name and full path.
This part of the scenario is currently working as intended, as I have modified the GetAssociatedData() method of the RadUploadData to pass back the file name, full path and MIME Type of the file I just uploaded. So in my code behind on the ChildWindow, I am creating a new record in the database for that Customer and the newly uploaded files.
I also have the list box populating correctly with the data that I want, by getting the name of the file from the database and its associated CustomerID. This is currently working as intended.
However, the part that I am stuck on is being able to display the uploaded files to the user, as I would like to handle the Click event of an item in the List Box and then show the file (whatever type it may be). I am currently doing this by going:
public FileUpload()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(FileUpload_Loaded);
}
void FileUpload_Loaded(object sender, RoutedEventArgs e)
{
PopulateFiles();
System.Windows.Threading.DispatcherTimer timer = new
System.Windows.Threading.DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(0.5);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
//HACK: Work around for handling a double click.
bool DoubleClick = false;
void timer_Tick(object sender, EventArgs e)
{
DoubleClick = false;
}
//NOTE: appcmd set config /section:staticContent /+"[fileExtension='.msg',mimeType='application/vs.microsoft_outlook']"
//To add a new MIME type to the client machine set this in Start -> Run -> CMD.
private void ListBox_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (DoubleClick && ((ListBox)sender).SelectedItem != null)
{
System.Windows.Browser.HtmlPage.Window.Navigate
(
navigateToUri:new Uri(http://localhost/Project.Web/UserUploads/ + ((sender as ListBox).SelectedItem as FileStore).FileName),
target:"_blank"
);
}
else if (!DoubleClick) { DoubleClick = true; }
}
This will work for most common file types (.png, .jpg, .txt files) as the Client's machine will know what the corresponding MIME Type for those are (for example, images/png, images/jpg, or plain/text). However, once I get into the more complicated file types, which need a proper application to open them (for example, Microsoft Outlook Saved Emails: .MSG files) because the MIME Type required for this kind of file is ‘application/vnd.ms-outlook’. If I use the above method of Navigate to this .MSG file, it fails because the newly opened browser does not know what to do with it as it does not have the ContentType like below.
I know how to do this in ASP.Net, but not sure about in Silverlight. In ASP.Net I do this like:
Dim file = (From data In DB.FileStores _
Where data.FileID = id _
Select data).FirstOrDefault
Me.Title = file.Title
Response.Clear()
Response.ContentType = "application/vnd.ms-outlook"
Response.AddHeader("Content-Disposition", "attachment; filename=" &
file.Title & file.Extension)
Response.BinaryWrite(file.FileData.ToArray)
Response.End()
So when this code runs, it will prompt the user to save the file to their local disk, and then open it as any normal file located on the local disk which is fine for this scenario.
If you need any more information other than what is provided here please don’t hesitate to ask.
Regards,
Shaun Sharples
Now I got it.
About the DoubleClick, one better approach for me is to keep the last click time in a field and when you encounter next click (mouse down) that is within 200ms from the lastClickedTime then you have DoubleClick. This way you don't need Timer and so much code and it works faster as well.
About the real problem - you can't do it with Navigate method, but I think that you can do this with JavaScript. You may call JS function in Silverlight, so the question is if you can use navigate in JS with content-type.
Unfortunately I'm not JavaScript guru, so you'd best try it yourself.
Please let me know if we can be of further help.
Miro Miroslavov
the Telerik team

Thanks very much for both of those suggestions, I have now got it working as I wanted. I am calling a JavaScript function, which navigates to an ASPX page including passing the FileID from the database, at which point I clear and write my own header content type and handle the files through that way.
Regards,
Shaun Sharples