Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 10th, 2005, 11:36 AM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default The process cannot access the file...

Good morning to you all....

I am getting the following error after I upload a file through ASP.NET, and then try to delete it:

The process cannot access the file "530.gif" because it is being used by another process.

When I kill the aspnet_wp.exe process I once again have access to manipulate the file.  I have scoured the Net to try and find a solution to no avail.  Anyone have any ideas?  Many thanks in advance.  Please find the code below.

Regards,
Eric

'Compile new file name
Dim sNFile As String = Request.QueryString("cid") & Path.GetExtension(sPath)
Dim sNPath As String = cfg.setting("PHYSICAL_PATH") & "data\" & sNFile
'Save file to server
Try
   newImg.PostedFile.SaveAs(sNPath)
Catch ex As Exception
   tStatus.Text = ex.Message
End Try
newImg.Dispose()



Dolphin Bay, Inc. -- turning visions into eReality(tm) -- West Palm Beach, FL
Website Design, Internet Strategy, Search Engine Marketing

www.dphin.com
  #2 (permalink)  
Old May 10th, 2005, 04:18 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I have experienced similar problems with a web application that reads images into stream readers and manipulates them. Despite thorough (at least what I though was thorough) closing and destruction of the objects used, IIS still held a lock on the files. Haven't solved it yet.

-Peter
  #3 (permalink)  
Old May 10th, 2005, 04:30 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

Peter,

Thank you for your thoughts. I am trying to work around this problem by simply uploading the file to a directory on the server and pointing to the image through a standard <img> tag. Only the path is being stored in the DB.

Once the file has been uploaded via .NET, the file is "locked" and cannot be manipulated at all through .NET or manually via the OS itself. I am not creating any reader.

Do you know of any way to simply upload files without IIS hanging onto them?

Many thanks,
Eric


Dolphin Bay, Inc. -- turning visions into eReality(tm) -- West Palm Beach, FL
Website Design, Internet Strategy, Search Engine Marketing

www.dphin.com
  #4 (permalink)  
Old May 10th, 2005, 04:53 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

IIS will always have to have a hold on the file you upload, at least at the point of upload. I'm not sure what the problem is with letting go of the lock as we have both found.

There aren't many options for uploading files apart from the way you are doing it. About the only other solution would be an FTP into the image location. But this isn't practical for web application users who aren't familiar with or don't have the tools for FTP.

-Peter
  #5 (permalink)  
Old June 18th, 2005, 10:15 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To get around this, you need to upload files initially to the ASP.Net temp directory, and from there you can manipulate them as needed. To get the path to the temp directory, call System.IO.Path.GetTempPath()
  #6 (permalink)  
Old November 8th, 2005, 11:56 AM
Authorized User
 
Join Date: Jun 2003
Location: New York, NY, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have just spent two days tackling a similar issue in ASP.

I created an ASP page that uses a database SELECT statement and html TABLE to create an Excel spreadsheet. To create the spreadsheet, I used:
 
  • Response.ContentType = "application/vnd.ms-excel"
  •   
  • Response.AddHeader "content-disposition","attachment; filename=MyFile.xls"


PROBLEM:
    First time user opens window and clicks on link, Excel spitout works GREAT!! Then the user closes their active window. Does not matter if they logout properly or not. When a new window is opened, and user logs back into the ASP app and tries to press link again, they then receive an error message:

        "Microsoft Excel cannot access the file 'http://www.myurl.com/dir1/excel_spitout.asp'. There are several possible reasons:
   
  • The file name or path name does not exist.
  •   
  • The file you're trying to open is being used by another program. Close the document in the other program, and try again.
      
  • The name of the workbook you're trying to save is the same as the name of another document that is read-only. Try saving the workbook with a different name."


WORKAROUND:
I discovered that, whenever the error occurred, I could click on ANY OTHER LINK on my ASP page - so long as it was a link that made a database request - and then press the BACK button, come back to my original page, and then press my Excel link again, and ... voila!! The link would suddenly work!

It would not, however, work if the link I pressed was an HTML only page or did not make a database request from the server / back-end database.

Clearly this indicated that the Excel object (or maybe some other object) was being retained in memory, and that opening a new db connection and executing a recordset seemed to wipe it out.

I Googled and Googled and the only good answer I found on this topic was that this was a known issue in XL97 and that Microsoft had created a patch for it.

See: http://support.microsoft.com/default...b;en-us;151064

Fat lot of good a service pack for XL97 would do me when I and most of my users are using XL2003.


CHEAP AND DIRTY RESOLUTION:
I hate that I did this, but seeing as how no one has come up with a "clean" way to resolve this, such as using code to determine if the Excel object is still open or not, and I could not figure out how to do so by myself, I opted for a cheap & dirty solution. I created a new ASP page, called whenever the user presses on the "Create Excel Spitout" link. This intermediary web page does nothing more than:
  • opens a database connection
     
  • creates a small recordset (does not matter what info is retrieved, so long as the database is engaged in activity)
      
  • executes it, then closes it, then ...
     
  • redirects user to the ACTUAL "Create Excel Spitout" link.

I offer this solution to anyone who has been driven MAD by the MS Office bug that creates this error!! This also is a challenge --> if any of you can come up with a more sophisticated solution, I would love to hear about it.

Hoping this helps someone,

Susan Henesy



Susan :)
  #7 (permalink)  
Old January 17th, 2007, 10:28 AM
Registered User
 
Join Date: Jan 2007
Location: , Warwickshire, United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi all,

This is by no means a fix - like many of you, I have coded and searched for an ideal solution to this bug but all attempts have proved to be fruitless - but this has worked for me.

Similar to MissHenesy, if prior to or after your attempt to work on the file, you force your application to do some sort of complex query this will release the lock held on the file by ASPNET or IIS (or both), allowing you to read, write, delete, etc.

As i said, by no means a fix (and certainly not ideal), but it works!

  #8 (permalink)  
Old July 28th, 2009, 03:05 AM
Registered User
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Alternative

Hi frndz,
I am facing the same problem, i have an alternative, set a bit field if you want to delete the file in DB, at certain time in a day run a batch file which can remove the images whose status will be deleted. While displaying such images before deletion check for status.

It may not be a solution but may an alternative.

Thanks.
  #9 (permalink)  
Old September 16th, 2009, 06:03 AM
Registered User
 
Join Date: Sep 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi..
I read your post and as per that i think one of your process remain as it is so from that when you try to run it on other side so you can not exist that file so first you have to check that by toolbar so you can solve out your problem.... Thanks for sharing the post....
  #10 (permalink)  
Old May 23rd, 2014, 05:38 AM
Registered User
Points: 30, Level: 1
Points: 30, Level: 1 Points: 30, Level: 1 Points: 30, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You receive a "The process cannot access the file because it is being used by another process" error message when you try to start a Web site in the Internet Information Services MMC snap-in Print Print Email Email
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
The process cannot access the file nelly78 .NET Framework 2.0 3 July 22nd, 2008 07:59 AM
The process cannot access the file while publishin madhu15583 ASP.NET 1.0 and 1.1 Professional 0 June 19th, 2008 02:58 AM
[Resolved] Error: File used by another process snufse .NET Framework 2.0 2 February 18th, 2008 09:20 AM
file error ...being used by another process rreynolds Pro VB.NET 2002/2003 6 January 11th, 2005 11:56 AM
DTS text file export - Batch Process Tim Barbour SQL Server DTS 1 November 23rd, 2004 11:50 AM



All times are GMT -4. The time now is 08:00 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.