Welcome Guest Search | Active Topics | Sign In | Register

Missing file extension on download Options
NNe
Posted: Thursday, May 8, 2014 11:23:26 AM
Rank: Member
Groups: Member

Joined: 4/12/2014
Posts: 15
If i have the following setting on Windows "hide extensions for known file types" CHECKED, the save file dialog proposed me to save the file without a extension. So if i try to open the file after the download operation, windows can't know what program can open the file.
Everything works correctly if the Windows option "hide extensions for known file types" is not checked.
eo_support
Posted: Saturday, May 10, 2014 8:47:26 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

When you use WebView to download file, your code is responsible for displaying "Save As" dialog and create the correct save as file name. If you do not create a save as file name with the proper extension, the file will be saved without extension. When the file is saved without extension, windows won't know what program to use to open the file.

The following code demonstrates how to use WPF SaveFileDialog to prompt user for a save as file name and ensure that it has the same extension as the file to be downloaded. Your code can be different, but the idea is you have to make sure the file name you pass to e.Continue is a file name with the proper extension.

Code: C#
//Use the system "Save As" dialog
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();

//Create two items in the "File Type" drop down: The first one is
//*.*, the second one is the *.xxx, where xxx is the extension of
//the file to be downloaded
string filter = "All Files (*.*)|*.*";
int filterIndex = 1;    //FilterIndex is 1 based
string ext = System.IO.Path.GetExtension(e.DefaultFileName);
if (!string.IsNullOrEmpty(ext))
{
	if (ext.StartsWith("."))
		ext = ext.Substring(1);
	filter += string.Format("|{0} Files|*.{0}", ext.ToUpper(), ext);
	filterIndex = 2;
	dlg.AddExtension = true;
}
dlg.Filter = filter;
dlg.FilterIndex = filterIndex;
dlg.FileName = e.DefaultFileName;

//Show the dialog and pass the result to e.Continue. The key is the
//file name you pass to e.Continue must have the proper extension
Nullable<bool> result = dlg.ShowDialog(this);
if (result.HasValue && result.Value)
	e.Continue(dlg.FileName);  
else
	e.Cancel();


Hope this helps.

Thanks!
NNe
Posted: Monday, May 12, 2014 10:44:38 AM
Rank: Member
Groups: Member

Joined: 4/12/2014
Posts: 15
Thank you very much! It works !
eo_support
Posted: Monday, May 12, 2014 12:17:58 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
You are very welcome. Please let us know if you have any more questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.