File access problem
-
hi all i have problem in file IO, if one of you can solve the problem i will very thank full to him/her... Description: i hv one page that enables the user to upload file, for that i use HttpInputFile control to receive posted file by user. i can save posted file but i can not delete that posted file, it is throwing an Exception "System.IO.IOException: The process cannot access the file ". another process 'aspnet_wp.exe' is accessing the same file. Code:
void SaveFile() { filInput.PostedFile.SaveAs(filename); //Validation code to check the file whether it is valid or not //if invliad delete the file and show message File.Delete(filename); // Error line }
Confidence comes not from always being right, but from not fearing to be wrong..... Mihir..
-
hi all i have problem in file IO, if one of you can solve the problem i will very thank full to him/her... Description: i hv one page that enables the user to upload file, for that i use HttpInputFile control to receive posted file by user. i can save posted file but i can not delete that posted file, it is throwing an Exception "System.IO.IOException: The process cannot access the file ". another process 'aspnet_wp.exe' is accessing the same file. Code:
void SaveFile() { filInput.PostedFile.SaveAs(filename); //Validation code to check the file whether it is valid or not //if invliad delete the file and show message File.Delete(filename); // Error line }
Confidence comes not from always being right, but from not fearing to be wrong..... Mihir..
Perhaps it's something similar to saving images, then you have to dispose of the image object before you can delete the file. There is no dispose method for uploaded files, though. Can't you just verify the data before you save it as a file? --- b { font-weight: normal; }
-
hi all i have problem in file IO, if one of you can solve the problem i will very thank full to him/her... Description: i hv one page that enables the user to upload file, for that i use HttpInputFile control to receive posted file by user. i can save posted file but i can not delete that posted file, it is throwing an Exception "System.IO.IOException: The process cannot access the file ". another process 'aspnet_wp.exe' is accessing the same file. Code:
void SaveFile() { filInput.PostedFile.SaveAs(filename); //Validation code to check the file whether it is valid or not //if invliad delete the file and show message File.Delete(filename); // Error line }
Confidence comes not from always being right, but from not fearing to be wrong..... Mihir..
Hi Mihir, To resolve this we have 2 ways One manin thign is make sure that Your virtual directory property directory access authentication is set to "Windows Integrated Authentication" another(this is not compulsary) is check weather that uploaded file attributes are read only or not. if read only remove like this
// remove readonly attribute of the file if ((f.Attributes & System.IO.FileAttributes.ReadOnly) != 0) { f.Attributes -= System.IO.FileAttributes.ReadOnly; } System.IO.File.Delete(f.FullName);
regards GV Ramana -
hi all i have problem in file IO, if one of you can solve the problem i will very thank full to him/her... Description: i hv one page that enables the user to upload file, for that i use HttpInputFile control to receive posted file by user. i can save posted file but i can not delete that posted file, it is throwing an Exception "System.IO.IOException: The process cannot access the file ". another process 'aspnet_wp.exe' is accessing the same file. Code:
void SaveFile() { filInput.PostedFile.SaveAs(filename); //Validation code to check the file whether it is valid or not //if invliad delete the file and show message File.Delete(filename); // Error line }
Confidence comes not from always being right, but from not fearing to be wrong..... Mihir..
thanks to both.. i have solved the problem.. problem was with SmartNavigation property of the page, i dont know why it is happening. i had set this property to True. By restoring the default value problem has solved. Confidence comes not from always being right, but from not fearing to be wrong..... Mihir..