Hey guys, this may seem like a really basic question but I just can't get my head around why it won't work!!
I have a form where the user can select a MS Word document to convert to XHTML and save this file in a different directory. However, I keep getting 'COMException was unhandled' on this line:
The error lies with the variable 'strFileName'
I have one method where the file dialog is opened, user selects file and strFileName is declared.
In another method I want to call strFileName, but I'm unsure how to do this. If I make the variables public I also need to make the file dialog public for this to work.
As I want strFileName to equal fDialog.FileName when I call it in the other method, if I declare at the top of the class it will obviously generate an error
Code:
public OpenFileDialog fDialog;
public string strFileName = fDialog.FileName;
How do I get the variable to be set to fDialog.FileName for the other methods?
Last edited by cjja; October 4th, 2010 at 03:47 AM.
Reason: strFileName needs to be set to fDialog.FileName
when you do this.. the fDialog.FileName does not contain the path .. it might have NULL value..
you just declare strFileName without initializing... and later in the when the user clicks on OK button then you will get the required path...
Yes but I need the variable to have this value when it is called in another method. If I declare it at the top as null the value called in the other method will be null.
I need it to have the filename the user selected from the file dialog.
Yes but I need the variable to have this value when it is called in another method. If I declare it at the top as null the value called in the other method will be null.
I need it to have the filename the user selected from the file dialog.
yup, you can do that , make sure the click method is called after the method where file dialog is open... so that the strFileName will have the file name value filled in it...
Yes but I need the variable to have this value when it is called in another method. If I declare it at the top as null the value called in the other method will be null.
It's sounds like you don't know what to do with that variable? Just make it a private member field of the class containing the method. You know what I'm talking about?
Bookmarks