.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

The process cannot access the file because it is being used by another process

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :.NET Framework

Hey all

This is annoying, I want to perform a copy or move or read operation on a file but the file is already open in word or notepad, whatever.

No when I try for example to rename the file that is open in word the system tells me that I can't do it since word holds it.

How can I do the same in C#, meaning checking if the file is open and alert which application holds it.


View Complete Post

More Related Resource Links

Error "The process cannot access the file ....." occurs while using function "ExportToStream"


Dear all,

   I sometimes get the following error while printing crystal report to pdf:

   System.Runtime.InteropServices.COMException (0x80004005): The process cannot access the file because
it is being used by another process. at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export
(ExportOptions pExportOptions, RequestContext pRequestContext) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream
(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
 at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options) at
 CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportFormatType formatType) at
 CommonWA.CommonFunc.GetPDFMemoryStream(DCMSReportDoc _dcmsreportdoc, Boolean& _DataExist) in E:\wwwroot\ASPWA\CommonWA\CommonCom.vb:line 382

  The error not occurs frequently but sometimes it will happen, can someone tell me why the error occurs and how can I solve the problem?

Thank you very much.


Restoring 2008 Database with Filestream - Process cannot access file error

I'm trying to restore a copy of a database that has a filestream and am getting the error below. I've tried with move option to specify a new path and left it with default path, neither worked. Did a trace with procmon, didn't see anything. FileStream1 is a new folder that the restore process creates. I've deleted the folder, tried it with a new name, re-took the backup from the source machine, restarted SQL, rebooted the machine, drive permissions are open. I've run out of ideas on how to debug further. Looking up the error online wasn't much help either. Msg 3634, Level 16, State 1, Line 1 The operating system returned the error '32(The process cannot access the file because it is being used by another process.)' while attempting 'OpenFile' on 'X:\Data\FileStream1\4ecb2e48-0eee-4c99-a3f0-f1e6c7f00b24\f2efe374-9481-4c1b-a7f2-dcdcee350807\0000001b-0000aaa6-00f6'. Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally. ' SQL Server 2008 SP 1, MS Server 2008 R2 Server

The process cannot access the file because it is being used by another process

I have an Excel Connection using the MS OLE DB provider for Office 12 and a Data Flow task to load the data. The filename is set dynamically with an Expression and some variables. The DFT runs fine, then there are a couple of steps that do NOT reference the Excel connection, then there is a File System Task set to MOVE the file to a \Loaded folder. I keep getting the error " The process cannot access the file because it is being used by another process There are no other processes that would be access this file other than the SSIS package itself. I even put in a Script task the pauses 30 seconds (just in case the Data Flow hasn't had enough time to release the connection). Still get the error. Once the package finishes with this error and I stop the debugging, I can manually execute the one Move File task and it goes OK. How do I get the DFT to release the hold on this file?Todd C - MSCTS SQL Server 2005 - Please mark posts as answered where appropriate.

FCB::Open: Operating system error 32(The process cannot access the file because it is being used by

Hello all,I am running into an interesting scenario on my desktop.  I'm running developer edition on Windows XP Professional (9.00.3042.00 SP2 Developer Edition).  OS is autopatched via corporate policy and I saw some patches go in last week.  This machine is also a hand-me-down so I don't have a clean install of the databases on the machine but I am local admin.So, starting last week after a forced remote reboot (also a policy) I noticed a few of the databases didn't start back up.  I chalked it up to the hard shutdown and went along my merry way.  Friday however I know I shut my machine down nicely and this morning when I booted up, I was in the same state I was last Wenesday.  7 of the 18 databases on my machine came up withFCB:pen: Operating system error 32(The process cannot access the file because it is being used by another process.) occurred while creating or opening file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf'. Diagnose and correct the operating system error, and retry the operation.and it also logs  FCB:pen failed: Could not open file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf for file number 1. OS error: 32(The process cannot access the file because it is being used by another process.).I've caught references to the auto close feature being a possible culprit, no dice as the databases in question are set to Fal

the process cannot access the file because it is being used by another process. asp.net



this is satish

I am getting exception "the process cannot access the file because it is being used by another process. asp.net",when i am uploading a image and saving to particular folder (folder name:uploaded_images).First time when i upload a image and save it to same folder its fine,but when i upload same image with same name and saving to same folder.Its nor overriding and i am getting this exception.

Here is my code:

string UploadFileFolderPath = "E:/webserver/Sai/V3/Saibook/Uploaded_Images";

            if (fileupload.PostedFile.FileName.ToString().Trim().Length > 0)
             filename = Path.GetFileName(fileupload.PostedFile.FileName);
             String filePath="E:/webserver/Sai/V3/Saibook/Uploaded_Images" + "/" + filename;                

                fileupload.PostedFile.SaveAs(UploadFileFolderPath + "/" + filename);

the process cannot access the file because it is being used by another process



Imports System.IO
Imports System.Data

Partial Class RTT_SaveAsTxt
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strfoldername As String = "C:\Txt\"
        Dim strfilename As String = "C:\Txt\users.txt"
        If Not Directory.Exists(strfoldername) Then
        End If
        If Not File.Exists(strfilename) Then
        End If
    End Sub

    Protected Sub btnSaveAsTxt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSaveAsTxt.Click
        If Not txtid.Text 

The process cannot access the file because it is being used by another process


Hi All

Iam getting the above said error while Iam copying a file of relativelly Heavy say 130 MB.

Below is the code which is giving the error.

System.IO.FileInfo FileInfo1 = new System.IO.FileInfo(filename1);

looking for the help very badly..



Help please. Process cannot access file.


Hi Gents,

Could I ask you for an advice, please?

I'm writing a Windows Application in C# VS 2003 .Net. The main purpose of the application is to switch folders. I will explain how it works below. When I run the application, click one button, it works. But when I click on some another button, it writes me this error:

"An unhandled exception of type "System.IO.IOException" occurred in mscorlib.dll. Additional information: The process cannot access the file "Data/DataSource/ver1.txt" because it is being used by another process."

Simplified code:

Structure (FYI)



exe/Data/DataSource/ver1.txt (ver1-3.txt) - the verX.txt tells the application which version (folder1-3) is renamed to Data/Work



exe/Data/Work - /folder1 is currently renamed to Work


If I press button1, run method button1();

If I press button2, run method button2();

If I press button3, run method button3();


run method deactivateVersion()



How to delete a file which was accessed by other process ?

Does Windows have a "unlock object" method in order to delete a file which is being used by another process ? Thanks

Import Error: Could not process the file Documents/Application Deployment.mht as a Single File Web P

Hi there everyone, Version: Windows Sharepoint Services 3.0 with Cumulative Update June 29, 2010 applied. I am having issues importing an exported site into a different domain. I've overcome most of the issues and actually got most of the site to import, however, the import process get's stuck on import a Single File Web Page document from a document library. I believe the original cause of this error is http://support.microsoft.com/kb/980079 The issue I face now is, I already have a large number of .mht files in my document library which I do need to import into the test environment (or that I might need to restore in a DR scenario). Does anyone have any information on either: forcing the import commmand to "on error resume next" (ie. not stop processing when it encounters an error) fixing the already corrupt .mht files in the database easily The error text from the import command is: Error: Could not process the file Documents/Application Deployment.mht as a Single File Web Page document. at Microsoft.SharePoint.Library.SPRequest.CreateOrUpdateFileAndItem(String bstrUrl, String bstrWebRelativeUrl, Guid& docId, Object varDoc, Int32 docLength, Int32 exists, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Int32 iVersion, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String checkInComment, Int3

How do i force SharePoint to open file automatically during check out process?

Currently, when checking out a file (doc., excel, pdf etc.) in Sharepoint, i right click on doc. and click "check out". Then a window pops up and saying " you are about to check out:...." and i choose the option of saving the file in my Local Drafts Folder. The issue is that the file does not open automatically once i click "ok" in pop up window. I have go back to file in SharePoint and click on it again to open it. How do i force SharePoint to automatically open the file, when i go through the check it out process? Thank you all for your feedback.

SSIS Execute Process Task Give "Access is Denied" error but it is not related to access control.

Hello All - I have a very weired SSIS problem. I am using BIDS in two machines - Windows 7 Professional Edition x64 bit (development workstation) and Windows 2003 Standard Edition x32 bit SP2 (server) . The visual studio version on both the machines are Version 2.0.50727 SP2. I found that my package's ExecuteProcessTask fails with "Access is denied" error in Windows2003 but runs ok in Windows 7 dev box. I then tried to debug the package in the Windows 2003 environment itself. The package failed in debug mode too with the same message. After looking for a while I found that when I shorten the Argument length of the failing ExecuteProcessTask the task did seem to work. So in Windows2003 environment if my argument exceeds 1846 characters the ExecuteProcessTask fails with message "Access is Denied". If the argument string is less than 1846 it works ok. In Windows 7 environment there is no problem at all. It does not seem like access problem but I may be wrong. Has anyone seen this? I will appreciate any reply. Thanks, Niben  

The process could not be created for step 1 of job .....(reason: The system cannot find the file spe


Hi ,

I was trying your options by using "(operating system) cmdExec" to delete folders which were 15 days olders.  But here i am getting error if i look into view history of sql agent job... below is my command that i gave in Job step.

EXEC xp_cmdshell 'forfiles /p "z:\backup" -d 15 /c "cmd /c if @isDir==True echo RD /Q /S @FILE&RD /Q /S @FILE"'

And the error is :

The process could not be created for step 1 of job .....(reason: The system cannot find the file specified).  The Step failed.

but if i give this command in New Query Window, i am able to delete the folders successfully.

Please advice me if am wrong

R Anand

.tmp file created after process crash when application upgraded to 2.0

After upgrading an asp.net application to 2.0 from 1.1 I am receiving a large 100+MB .tmp file in C:\Temp on the web server when the w3wp process serving that application crashes. If you open the file it looks like it is some sort of dump file. Any ideas how to turn this off. I know what is crashing the application and process. Any help is appreciated. Thanks

check file size before uploading process in c# with asp.net


Hi All,

Thank you for Advance.

currently we are configured execution Timeout="1200" (The default is 110 seconds)  and maxRequestLength="12288"  (The default is 4096 KB)

but some times users upload files above 12MB so we are getting "Maximum request length exceeded" error.

we are checking the file size using client side javascript ActiveXObject object. but ActiveXObject only works in IE not in others like mozilla,crome,...

Jacescript Code are

function GetSize(file)
  var fso=new ActiveXObject("Scripting.FileSystemObject");
  var f=fso.getFile(file);
  return fso.getFile(file).size;


how can i check the file size before uploading process with support all the browser.

any posiblities for checking file size before server side script/object?


SharePoint 2010 Incoming Email cannot process email file attachment in email with less than sign < a


When sending an email which contains an email attachment such as "Hello <World>.msg" from Outlook to SharePoint 2010 email enabled list such as an "Announcements" list, no item is created in the list and the attached email and the orginal email are not saved.

The log file contains

09/23/2010 13:51:17.54  OWSTIMER.EXE (0x18FC)                    0x0B2C SharePoint Foundation          E-Mail                         6873 Warning  An error occurred while processing the incoming e-mail file C:\inetpub\mailroot\Drop\f17ce37101cb5b600000002a.eml. The error was: Illegal characters in path.. 9f265722-74c9-4bd8-9504-ac265f2351d7

SharePoint 2010 Incoming Email cannot process file attachment with zero size.


When sending email with attachments to SharePoint list, if one of the file attached to the email is of size 0, then none of the files will be saved and NO new item will be created in the list.

The SPEmailHandler's ProcessAttachment method should check the length of the "contentStream". If the length is 0, it should return immediately.

As you can see in the ProcessAttachment method none of the arguments are validated before they are used. This an example of poor quality code.

It should do at least

if (contentStream == null || contentStream.Length == 0) return;

if (string.IsNullOrEmpty(fileName) || item == null) return;


private static void ProcessAttachment(Stream contentStream, 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend