Skip to main content
Home Forums General Silverlight New Features in Silverlight 3 OpenFile() method of SaveFileDialog always throw an IOException
24 replies. Latest Post by Moe Elshall on March 31, 2009.
(0)
Thomas L...
Member
45 points
52 Posts
03-27-2009 11:54 AM |
Hi,
In my application, I'm trying to use the SaveFileDialog but every time I call the OpenFile method (to get access to the stream), it throws an exception of type IOException with the following message: "The directory name is invalid.". Looking at the property File give me some informations but everything looks fine (path, properties, etc.)
Here is the sample code I'm trying to use (in bold, it's the portion of the code which launch the exception)
var sfd = new SaveFileDialog { DefaultExt = "csv", Filter = "CSV Files (*.csv)|*.csv|All Files|*.*" }; if (sfd.ShowDialog().Value) { using (var writer = new StreamWriter(sfd.OpenFile())) { } }
I've tried on a fresh application, I've tried to save the file on differents path, etc. I'm using Windows Vista and I'm administrator of my machine.
I've also tried some other applications which provide the same feature (like here: http://www.silverlightshow.net/items/Using-the-SaveFileDialog-in-Silverlight-3.aspx) but the result is the same: an exception with the message "The directory name is invalid".
Any ideas ?
Thanks !
Fredrik N
Participant
804 points
147 Posts
03-28-2009 5:10 AM |
Hi Thomas,
I copied your code and it worked fine, no exception. I'm using the Silverlight 3.0 Beta and Visual Studio 2008 SP1 on Windows Vista x64.
My first thought was that the directory you last saved a file to, will be the one that the Dialog try to use.. If that folder was removed, it could throw an exception, but that wasn't the case.
I know that this reply doesn't help you so much, but at least you know that it worked for me ;)
03-28-2009 12:44 PM |
Hi Fredrik,
Yes, I know that my code should work fine but as you can read, it's not the case on my machine.
It looks like an issue but I don't know where/why because all other feature work fine :(
Thanks anyway !
03-30-2009 3:32 AM |
Anyone got an idea ? A similar problem ?
codeblock
Contributor
4060 points
716 Posts
03-30-2009 5:11 AM |
are you sure you launch the SaveFileDialog from an user-initiated event? (e.g. Button click).
03-30-2009 5:16 AM |
Yes, the code i'm trying to use (and that works fine) is called on the click event handler of a button...
Thanks.
03-30-2009 8:56 AM |
I've tryied and get no error. I did this test:
1) created a Page with default Grid2) Added a Button and the click handler3) Add your code in the click handler4) run5) dialog opens and file was created.
give us more detail please... (the directory you choice, the file name) and if possible a source code to reproduce behaior
HTH
03-30-2009 9:06 AM |
I've tested with different values: i've tried to save the file in a directory on C:\, on D:\, on my desktop, on my documents, etc.. with differents filename: test.xls, temp.xls, etc... Every time, I get the same exception.
I think it's an issue (maybe with my SL3 runtime installation ?) because even this code does not work: http://www.silverlightshow.net/items/Using-the-SaveFileDialog-in-Silverlight-3.aspx
The code I'm trying is pretty simple:
private void Button_Click(object sender, RoutedEventArgs e) { var sfd = new SaveFileDialog { DefaultExt = "csv", Filter = "CSV Files (*.csv)|*.csv|All Files|*.*" }; if (sfd.ShowDialog().Value) { using (var writer = new StreamWriter(sfd.OpenFile())) { // } } }
Do you need my sample application ?
03-30-2009 9:19 AM |
> I think it's an issue (maybe with my SL3 runtime installation ?) because even this code does not work:
I think that we have to consider that your installation has something wrong. The code you posted is exactly the same I wrote.
May you try to reinstall a fresh dev machine?
03-30-2009 9:26 AM |
Well, I've tried to reinstall the SL3 Runtime but it still does not work...
StefanWick
2864 points
438 Posts
03-30-2009 9:37 AM |
What browser/OS are you running on.Do you have active scripting enabled?
Thanks, Stefan Wick
03-30-2009 10:00 AM |
Hi Stephan,
I'm using Windows Vista Business Edition with Internet Explorer 7.
I've try with active script enabled and disabled: same results.....
03-30-2009 10:55 AM |
I have Windows 7 with IE8. I'm trying a guess: may you try disabling UAC?
03-30-2009 1:45 PM |
I've just give it a try but it's the same result :(
03-30-2009 2:41 PM |
I've finished the ideas... :(
03-31-2009 3:06 AM |
OK so that's really strange
I've tried everything: reinstall the plugin, reboot the machine, try a different browser. But every time, I encounter the same error when my code try to use the OpenFile method....
veenar
46 points
15 Posts
03-31-2009 3:42 AM |
can you try out DialogResult.OK instead of .Value
{
}
03-31-2009 3:50 AM |
ShowDialog returns a object of type bool? (nullable of bool) and I can't use DialogResult....
Moe Elshall
188 points
29 Posts
03-31-2009 4:22 AM |
Are you running IE in protected mode?
For IE to be running in protected mode, UAC must be on and Protected Mode should be enabled "IE -> Tools -> Internet Options -> Security -> Enable Protected Mode"
If you're running in Protected Mode...switch to non-protected mode and see if it works.
If not, please switch to protected mode.
This is not a proposed fix, I'm trying to troubleshoot the root cause.
Thanks,Moe
03-31-2009 5:32 AM |
Hi Moe,
This works fine, thanks a lot !
BTW, I'm not sure this is a good way to do it but it works for now, thanks !
mmatos
10 points
5 Posts
03-31-2009 10:53 AM |
Can you clarify whether you moved from protected mode TO non-protected mode or vice versa?
Thanks so much.
03-31-2009 11:13 AM |
Hi Marco,
I moved from Protected Mode Activated to Protected Mode Desactivated for the Local Intranet Zone.
HTH !
03-31-2009 11:18 AM |
Great data point for our debugging thanks!
Also, you mentioned you did this for the intranet zone. Is that where your xap is being hosted from? I know you mentioned you were saving to the local machine but just curious what the SL client is being served from. This also might shed some more light on the problem.
03-31-2009 11:25 AM |
The XAP file is hosted on my local machine: I've just create a Silvelright application (and Web application) using Visual Studio and try the code I've mentionned above.
Then, when I debug, Cassini (the Web Server inside Visual Studio) is launched and I access to my XAP from the URL: http://localhost:XXX/MyApp.xap
03-31-2009 12:01 PM |
Thanks Thomas.We’ll see what we can do to fix this. Please mark the question as answered.
~Moe
Silverlight Development Team
Microsoft