Copying file error.
-
Hi m trying to copy image file from one location to other as below in openDialog box C#.net
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = System.IO.Path.GetFileName(openFileDialog1.FileName);string fname = Application.StartupPath + "\\\\Temp\\\\" + filename; File.Copy(openFileDialog1.FileName, fname, true);
}
I get Exception as Unknown software Exception(0xe0434f4d) ocurred in application at location 0x7c59bcb1 It works for all files except for .bmp file Ne help for it?
I don't see anything obviously wrong, so the next step should be to get more information about the bug. See what the values are for OpenFileDialog.FileName and fname. If they look ok, put a try/catch around this, and display the message on the exception.
-
Hi m trying to copy image file from one location to other as below in openDialog box C#.net
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = System.IO.Path.GetFileName(openFileDialog1.FileName);string fname = Application.StartupPath + "\\\\Temp\\\\" + filename; File.Copy(openFileDialog1.FileName, fname, true);
}
I get Exception as Unknown software Exception(0xe0434f4d) ocurred in application at location 0x7c59bcb1 It works for all files except for .bmp file Ne help for it?
Hi, did you bother looking at the values of filename and fname? IIRC OpenFileDialog.FileName returns a file path, so your fname would be garbage. FYI: (sub)folders of a StartupPath may be write-protected. You should consider using Environment.GetFolderPath() :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
You should trap the exception in a Try Catch block and see what the actual error is. That exception's generic and it could be anything.
I have trapped the exception in try catch block.
-
I don't see anything obviously wrong, so the next step should be to get more information about the bug. See what the values are for OpenFileDialog.FileName and fname. If they look ok, put a try/catch around this, and display the message on the exception.
I have debugged the code i get proper values in filename and fname
-
Hi, did you bother looking at the values of filename and fname? IIRC OpenFileDialog.FileName returns a file path, so your fname would be garbage. FYI: (sub)folders of a StartupPath may be write-protected. You should consider using Environment.GetFolderPath() :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
I have debugged the code i get proper values in filename and fname. Folders and file have all permissions
-
Hi m trying to copy image file from one location to other as below in openDialog box C#.net
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = System.IO.Path.GetFileName(openFileDialog1.FileName);string fname = Application.StartupPath + "\\\\Temp\\\\" + filename; File.Copy(openFileDialog1.FileName, fname, true);
}
I get Exception as Unknown software Exception(0xe0434f4d) ocurred in application at location 0x7c59bcb1 It works for all files except for .bmp file Ne help for it?
More of a FYI than an answer , but you should always put the checked for value first:
if (DialogResult.OK == openFileDialog1.ShowDialog())
{
string filename = System.IO.Path.GetFileName(openFileDialog1.FileName);
string fname = Application.StartupPath + "\\Temp\\" + filename;
File.Copy(openFileDialog1.FileName, fname, true);
}that way if you mess up and only type one = you'll get an error during compile. This show what I mean:
int num = 3;
if (num = 4)
{
//num will be equal to 4 and this block always executes
}vs
int num = 3;
if (4 = num)
{
//You could never build this file without an error because you can't assign to an int value
}
-Spacix All your skynet questions[^] belong to solved
I dislike the black-and-white voting system on questions/answers. X|
-
Hi m trying to copy image file from one location to other as below in openDialog box C#.net
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = System.IO.Path.GetFileName(openFileDialog1.FileName);string fname = Application.StartupPath + "\\\\Temp\\\\" + filename; File.Copy(openFileDialog1.FileName, fname, true);
}
I get Exception as Unknown software Exception(0xe0434f4d) ocurred in application at location 0x7c59bcb1 It works for all files except for .bmp file Ne help for it?
asma_panjabi wrote:
I get Exception as Unknown software Exception(0xe0434f4d) ocurred in application at location 0x7c59bcb1 It works for all files except for .bmp file Ne help for it?
And if you try another .bmp, same effect? Maybe the BMP is malformed or something. Does the Temp directory exists?
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
I have trapped the exception in try catch block.
The exception has a Message member. What is the message when you get this exception?
-
asma_panjabi wrote:
I get Exception as Unknown software Exception(0xe0434f4d) ocurred in application at location 0x7c59bcb1 It works for all files except for .bmp file Ne help for it?
And if you try another .bmp, same effect? Maybe the BMP is malformed or something. Does the Temp directory exists?
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Other bmp files work properly even the temp folder exists only some bmp files dnt work
-
Hi m trying to copy image file from one location to other as below in openDialog box C#.net
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = System.IO.Path.GetFileName(openFileDialog1.FileName);string fname = Application.StartupPath + "\\\\Temp\\\\" + filename; File.Copy(openFileDialog1.FileName, fname, true);
}
I get Exception as Unknown software Exception(0xe0434f4d) ocurred in application at location 0x7c59bcb1 It works for all files except for .bmp file Ne help for it?
This is the error m getting System.UnauthorizedAccessException: Access to the path "C:\Documents and Settings\abc\Desktop\Debug\Temp\mani.bmp" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite) at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)