Skip to main content

Microsoft Silverlight

Answered Question OpenFile() method of SaveFileDialog always throw an IOExceptionRSS Feed

(0)

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

OpenFile() method of SaveFileDialog always throw an IOException

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 !

 

 

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

Fredrik N
Fredrik N

Participant

Participant

804 points

147 Posts

Re: OpenFile() method of SaveFileDialog always throw an IOException

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 ;)

 

/Fredrik Normén - fredrikn @ twitter

ASPInsider

Microsoft MVP, MCSD, MCAD, MCT

ASPInsiders
My Blog

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: OpenFile() method of SaveFileDialog always throw an IOException

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 !

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: OpenFile() method of SaveFileDialog always throw an IOException

Anyone got an idea ? A similar problem ? Sad

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

codeblock
codeblock

Contributor

Contributor

4060 points

716 Posts

Silverlight MVP

Re: OpenFile() method of SaveFileDialog always throw an IOException

are you sure you launch the SaveFileDialog from an user-initiated event? (e.g. Button click).

If this answers your question, please "mark it as answer"

--
Andrea Boschin
MVP Silverlight & Silverlight Insider
, Me on Twitter

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: OpenFile() method of SaveFileDialog always throw an IOException

Hi,

Yes, the code i'm trying to use (and that works fine) is called on the click event handler of a button...

 

Thanks.

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

codeblock
codeblock

Contributor

Contributor

4060 points

716 Posts

Silverlight MVP

Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

I've tryied and get no error. I did this test:

1) created a Page with default Grid
2) Added a Button and the click handler
3) Add your code in the click handler
4) run
5) 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

If this answers your question, please "mark it as answer"

--
Andrea Boschin
MVP Silverlight & Silverlight Insider
, Me on Twitter

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

Hi,

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 ?

 

Thanks !

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

codeblock
codeblock

Contributor

Contributor

4060 points

716 Posts

Silverlight MVP

Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

> 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?

HTH

If this answers your question, please "mark it as answer"

--
Andrea Boschin
MVP Silverlight & Silverlight Insider
, Me on Twitter

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

Well, I've tried to reinstall the SL3 Runtime but it still does not work...

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

StefanWick
StefanWick

Contributor

Contributor

2864 points

438 Posts

Microsoft

Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

What browser/OS are you running on.Do you have active scripting enabled?

Thanks, Stefan Wick

Microsoft Silverlight | http://blogs.msdn.com/swick/

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

Hi Stephan,

 

I'm using Windows Vista Business Edition with Internet Explorer 7.

 

I've try with active script enabled and disabled: same results.....

 

Thanks !

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

codeblock
codeblock

Contributor

Contributor

4060 points

716 Posts

Silverlight MVP

Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

I have Windows 7 with IE8. I'm trying a guess: may you try disabling UAC?

HTH

If this answers your question, please "mark it as answer"

--
Andrea Boschin
MVP Silverlight & Silverlight Insider
, Me on Twitter

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

I've just give it a try but it's the same result :(

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

codeblock
codeblock

Contributor

Contributor

4060 points

716 Posts

Silverlight MVP

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

I've finished the ideas... :(

If this answers your question, please "mark it as answer"

--
Andrea Boschin
MVP Silverlight & Silverlight Insider
, Me on Twitter

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

OK so that's really strange Surprise

 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.... Sad

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

veenar
veenar

Member

Member

46 points

15 Posts

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

can you try out DialogResult.OK instead of .Value

 if (sfd.ShowDialog()== DialogResult.OK)

{

using (var writer = new StreamWriter(sfd.OpenFile()))

{

MessageBox.Show(writer.ToString());

}

 

}

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

ShowDialog returns a object of type bool? (nullable of bool) and I can't use DialogResult....

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

Moe Elshall
Moe Elshall

Member

Member

188 points

29 Posts

Answered Question

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

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

If this answers your question, please mark the reply as "Answer"

Moe Elshall | Silverlight Development Team
Microsoft Corporation

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

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 !

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

mmatos
mmatos

Member

Member

10 points

5 Posts

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

Can you clarify whether you moved from protected mode TO non-protected mode or vice versa?

Thanks so much.

Marco Matos

http://blogs.msdn.com/matos/
Silverlight PM
Microsoft Corporation

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

Hi Marco,

 I moved from Protected Mode Activated to Protected Mode Desactivated for the Local Intranet Zone.

 

HTH !

 

Thanks.

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

mmatos
mmatos

Member

Member

10 points

5 Posts

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

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.

Marco Matos

http://blogs.msdn.com/matos/
Silverlight PM
Microsoft Corporation

Thomas Lebrun
Thomas L...

Member

Member

45 points

52 Posts

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

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

 

Thanks !

-------------
Thomas LEBRUN
MVP Client Application Development / MCPD / MCT
INETA Bureau Speaker
Blogs: http://weblogs.asp.net/thomaslebrun/default.aspx (US) - http://blogs.developpeur.org/tom (FR)

Moe Elshall
Moe Elshall

Member

Member

188 points

29 Posts

Answered Question

Re: Re: Re: Re: OpenFile() method of SaveFileDialog always throw an IOException

Thanks Thomas.We’ll see what we can do to fix this. Please mark the question as answered.

~Moe

Silverlight Development Team

Microsoft

If this answers your question, please mark the reply as "Answer"

Moe Elshall | Silverlight Development Team
Microsoft Corporation
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities