Can not create file using FileStream in release mode
-
Dear all, This is my situation: I try to create text file by using below code: using (FileStream fs = File.Create(path)){}; It runs ok at debug mode, file is create at [path]. But nothing happens at release mode. What wrong with this code? Pls. explain for me if you know.
-
Dear all, This is my situation: I try to create text file by using below code: using (FileStream fs = File.Create(path)){}; It runs ok at debug mode, file is create at [path]. But nothing happens at release mode. What wrong with this code? Pls. explain for me if you know.
you should put that in a try-catch and look at the Exception.ToString(). what is the exact content of path? does the path exist? (if relative, it could be different in release vs debug) Which Windows edition? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
you should put that in a try-catch and look at the Exception.ToString(). what is the exact content of path? does the path exist? (if relative, it could be different in release vs debug) Which Windows edition? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Thank for your reply. About your question, I answer as below: - I also put the try-catch & look for Exception, but there is no exception. - The path is absolute path: C:\Program Files\MyFolder and it is existed. - I run in Window XP, VisualStudio 2003.
If you are trying to write to Program Files it could be a permissions issue. I would try another path that is definately going to accessible such as:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
To get the path you're using ath the moment I would do it this way:
string folderPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "MyFolder");I doubt that is related to your problem but may avoid problems in future.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Thank for your reply. About your question, I answer as below: - I also put the try-catch & look for Exception, but there is no exception. - The path is absolute path: C:\Program Files\MyFolder and it is existed. - I run in Window XP, VisualStudio 2003.
ndkit wrote:
Window XP
That is OK, and will not add unexpected limitations to what you can and can't do.
ndkit wrote:
VisualStudio 2003
So you are using .NET 1.1? I haven't used that for many years now, and I never will target it again. By all means, consider switching to .NET 2.0 (or higher). I'm not saying your problem is directly related, however 2.0 is much better than earlier versions, both in quality and functionality. If you don't have VS 2005/2008/2010 available, you might try using VS 2010 C# Express Edition, which is free and can be downloaded here[^]. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.