While Trying To Download A File : The Process Cannot Access The File Because It Is Being Used By Another Process
Oct 17, 2010
I am trying to download a file from the server but i am getting this error:
The process cannot access xxxx the file because it is being used by another process
This is my CODE:
string fileName="DownLoadFiles";
string filePath = hid_filepath.Value;
FileInfo file = new FileInfo(filePath);
System.Net.WebClient wc = new System.Net.WebClient();
wc.DownloadFile(new Uri(fileName, filePath);
Foe ur Information:the file is not opened or not used.
I've developed a popup email .aspx used on our intranet based web app that is auto generated with .pdf's attached. I'm developing with VS 2008 ASP.Net 3.5 C# and System.Net.Mail.MailMessage. I can create and send the email with no issues. The problem is with any attempt to open or delete the attachments I get the above error. The .pdf's a copied with the following code:
FileStream fsr = new FileStream(inFilename, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader reader = new BinaryReader(fsr); byte[] bytes = new byte[fsr.Length]; reader.Read(bytes, 0, bytes.Length); FileStream fsw = new FileStream(outFileName, FileMode.Create, FileAccess.Write, FileShare.Write); BinaryWriter writer = new BinaryWriter(fsw); writer.Write(bytes, 0, bytes.Length); // clean up writer.Flush(); writer.Close(); writer = null; fsw.Close(); fsw.Dispose(); fsw = null; reader.Close(); reader = null; fsr.Close(); fsr.Dispose(); fsr = null; Later after sending the email I: mailMessage.Dispose(); mailMessage = null; foreach (string fileName in attachments) { if (File.Exists(fileName)) File.Delete(fileName); }
The error occurs at: the File.Delete(fileName);
how I can delete or reopen these files after sending the email?
My code is that I want to create a log file and log it upon a new user browsing the site. However, what i did was I put in a 6 second delay and then used another browser to access the page. And it threw an Exception saying it is being used by another process which is true. So how come I set it so that, if IT is being used by another process, WAIT and retry every 500 milliseconds until it becomes free/available?
here's the code:
protected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) // if this is the first time page loads, set k to 1 { lognewuser(); }}
I am having the text file which is used to track all the ip address which is available in the network and replace the content from"Reply from 172.29.116.3: bytes=32 time=1ms TTL=255" to 172.29.116.3.
For this task i am having 2 functions 1.runCMD() Function is used to create a file which ping all the ip address between 3 to 254 ("Reply from 172.29.116.3: bytes=32 time=1ms TTL=255").
2.Another function textFileReplace() which is used to replace the text from "Reply from 172.29.116.3: bytes=32 time=1ms TTL=255" to 172.29.116.3.
This process will continue every 30 minutes..
But i am having the error while accessing the function textFileReplace() as The process cannot access the file 'C:inetpub' because it is being used by another process.
When I delete all files from the directory path. then it will give me this error The process cannot access the file because it is being used by another process. How to solve this?
I am getting binary data from a SQL Server database field and am creating a document locally in a directory my application has permissions. However I am still getting the error specified in the title. I have tried numerous suggestions posted on the web including those suggested in previous posts on Stackoverflow. I have also used ProcessExplorer > Find Handle to locate the lock and it returns nothing as if the file is not locked.
I am using the code below to save the file to the file system and I then try to copy this file to a new location later in the application process within another method. It is this copy method that takes the path of the newly created file that throws the exception.
The file itself is created with its content and i can open it through Windows Explorer without any problems.
Am I missing something completely obvious? Am I creating the file correctly from the database?
// Get file from DB FileStream fs = new FileStream( "C:myTempDirectorymyFile.doc", FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter br = new BinaryWriter(fs); br.Write("BinaryDataFromDB"); fs.Flush(); fs.Close(); fs.Dispose(); // Copy file File.Copy(sourceFileName, destinationFilename, true);
I am using a AsyncUpload(telerik), i am in a point where i am supposed to save the File to a certain Folder. First I check if the directory exist
Code: Dim baseDire As String = Server.MapPath("~/MyFILES/") If IO.Directory.Exists(baseDire & Request("Req_ID").ToString()) = False Then IO.Directory.CreateDirectory(baseDire & Request("Req_ID").ToString()) End If
Because i am doing multiple Upload , i will have to loop through the items of the Upload control and save to a folder.
Code: For Each file As UploadedFile In UploadPropDoc.UploadedFiles Dim bytes(file.ContentLength - 1) As Byte file.InputStream.Read(bytes, 0, file.ContentLength) 'Save the File to the disk file.SaveAs(baseDire + file.GetName()) Next
Now when ever i debug this , when it comes to this line
Code: file.SaveAs(baseDire + file.GetName())
I get an Error
The process cannot access the file because it is being used by another process.
I have removed the Readonly in the Folder that it supposed to write to and gave everyone permission , but still the error persist.
If I watch the processes tab in Task Manager on the web server I see "cmd.exe" under the context of 'administrator' but it just hangs. For test purposes c:SendV80s.bat: copy c: oot.ini c:zzz.txt
If I logon onto the webserver's console and execute SendV80s.bat it works and exits without issue. But when I execute the same batch file via the Submit button it gets stuck executing in Task Manager/Process. I believe this has something to do with the fact that cmd is not running in a full environment/desktop context. I just noticed this on the actual console of the webserver (not in my RDP console but console 0 instead)
A pop-up box stating: CMD.exe Application error The application failed to initialize properly (0xc0000142). Click OK to terminate the application. And when I click on the OK button my ASPX page's WaitForExit is satisfied and the continues processing normally.
I simply want to create one file and then delete it, means I want to access one file subsequently. I am getting the very familiar error as shown in title. (Process can't access the file,) I have tried using file stream and all other stuff that I found from Googling but no success so far. Does any body have small and neat solution? in short, I would like to run the following statements without any error.File.Create("C:\hsp1.txt");
I'm trying to write a text file form my web page, But every time I'm having this error System.IO.IOException: The process cannot access the file '.txt' because it is being used by another process. This is mode code for write file.
The process cannot access the file 'D:InetPubReefJunkiesUsersillProfilePicture Thumb340x_la-rouxsmall.jpg' because it is being used by another process.
Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The process cannot access the file 'D:InetPubReefJunkiesUsersillProfilePicture Thumb340x_la-rouxsmall.jpg' because it is being used by another process.
I am using an httpapi and i get an xml output in return from that. I am newbie to this and dont know how to process the returned xml. Kindly advice how to use this online xml file into my application to display to the user . The format of xml file is as follows :-
I have a folder called GUI. Inside GUI thers another folder called PDF and inside this folder, there are some PDF files. This folder (GUI) is uploaded to the server too. Then I have a WebForm with some ImageButtons. When I click one of these ImageButtons, I want the file to open in a new tab. I tried with the following code:
[Code]....
As you can see, I build the path using the tooltips of the different ImageButtons. The ToolTip = File Name I want to open. When I try this in debug mode, it works. It opens the pdf file in a new tab. However when I publish my website and upload it to the server... it doesn't work... when I click an ImageButton I get the following exception: No application is associated with the specified file for this operation
Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation Source Error:
[Code]....
Stack Trace:
[Code]....
[Win32Exception (0x80004005): No application is associated with the specified file for this operation] LandingSite.LnkRelease1_Click(Object sender, EventArgs e) +215 System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +108 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +118 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 Version Information: Microsoft .NET Framework Version:2.0.50727.3607; ASP.NET Version:2.0.50727.3082
I have Online Exam application when the user has completed his exam is write the question, answer and his result in the excel sheet and store it in server path. The admin has the option to reset the user ie the file gets deleted from the server. It works fine when Admin resets the file after some minutes but if Admin tries to reset the files in as soon as the exam is completed then i get the exception like "File Cannot be deleted since its used by another process" .
1. Will it work when i kill the Excel.exe in the server after the file completes the process or is there any optimul way to do the same.
I have a project with C# ASP.Net. I should create a web site which has categories.There will be a button and textbox and when I click this button there will be created a new web page and button and what I wrote text box it will be new button's text. At the same time, this created button's text will saved at SQL Server.I tried a create new button on page load but when I execute the project the button was created but I want to create with another button.These are for buttons; and these are for a new web page;(but there is an error -->Sayac.txt is already using)
I'm uploading an excel file and viewing it in a grid. But if I need to upload the file again in a couple of minutes I get an error that the file is being used by another process, so I cannot upload the file again. The file is always the same name.
i am using a data list with link button in it that is dynamically populated by String list. i can get accurate path of the clicked link button from the data list, and the next step is to open that document. i am using process.start() method to open pdf file but it does not open that file.i am using the following code to open pdf file from specific path. Code: protected void lnkbtnFirstQtrly_Click(object sender, EventArgs e) { try { //dirCustom is the DirectoryInfo variable that is global variable.
In my ASP.Net page, I allow users to download files from the server. If the file is of even a moderate size (does it with a 40 meg file, for example), when downloading, it fails with the error message:
"Insufficient system resources exist to complete the requested service".
I've checked out the server, and it's quiet (CPU, RAM, Hard Drive, Task Manager Processes, etc all very low in their numbers).
I've run the code from several client machines and I'm getting this error message no matter where I run it from.
I'm using the System.Diagnostics.Process class to run a batch file. I need to be able to take an output from the batch file and then display it on the web-page, basically to know if it succeeded or not, since the batch runs an .exe that doesn't always succeed.
the values returned by the .exe and have the batch run a script depending on the value returned. The script could be a VBscript that sends info to the webpage, but even then I'm not sure how to accomplish this.