473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

File Handling in ASP.Net / VB.Net

C
Hi,

I have a web app whereby I extract some data from an
Excel Sheet.

Once I have extracted my data I close my Excel Object.

I then try to delete the file.

When I try to delete the file it tells me that it is
locked by the IUSR account.

Anyone know why this is?

Thanks,
C
Nov 18 '05 #1
2 1605
A file is locked when it is opened by a process, and remains locked until it
is closed. Apparently, although you didn't mention how, you're opening the
file at some point. How are you opening it? Are you closing it prior to
attempting to delete it?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"C" <an*******@discussions.microsoft.com> wrote in message
news:08****************************@phx.gbl...
Hi,

I have a web app whereby I extract some data from an
Excel Sheet.

Once I have extracted my data I close my Excel Object.

I then try to delete the file.

When I try to delete the file it tells me that it is
locked by the IUSR account.

Anyone know why this is?

Thanks,
C

Nov 18 '05 #2
Closing an Excel Application object with COM Interop is
actually a bit tricky. Try code like this:

Private Sub ReleaseCOMObject(ByVal pobj as Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject
(pobj)
Catch
Finally
pobj = Nothing
End Try
End Sub

Private Sub ReadExcelFile()
Dim objApplication As Excel.Application
Dim objWorkbooks As Excel.Workbooks
Dim objWorkbook As Excel.Workbook
Dim strFileName as String
Try
strFileName = "ExcelFile.xls"
objApplication = New Excel.Application
objApplication.DisplayAlerts = False
objWorkbooks = objApplication.Workbooks
objWorkbooks.Open(strFileName)
objWorkbook = objWorkbooks(1)
' Work with data, making sure to use explicitly
' defined objects for each object or collection
' accessed.
' objWorkbook.SaveAs(strFileName & ".htm", 44)
objWorkbook.Close(False)
Catch ex as Exception
' Display error
Finally
ReleaseCOMObject(objWorkbook)
ReleaseCOMObject(objWorkbooks)
Try
objApplication.Quit()
Catch
End Try
ReleaseCOMObject(objApplication)
Try
Kill(strFileName)
Catch ex as Exception
' Display reason why file could not be deleted
End Try
End Try
End Sub
- Dave Davidson (MCP)
-----Original Message-----
Hi,

I have a web app whereby I extract some data from an
Excel Sheet.

Once I have extracted my data I close my Excel Object.

I then try to delete the file.

When I try to delete the file it tells me that it is
locked by the IUSR account.

Anyone know why this is?

Thanks,
C
.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
1
by: Sean W. Quinn | last post by:
Hey folks, I have a question regarding file handling, and the preservation of class structure. I have a class (and I will post snippets of code later in the post) with both primitive data...
5
by: John Douglass | last post by:
I'm fairly new to doing involved file i/o and I came across something weird with a program I'm writing (modifying MIDI data, if it makes any difference). With some input files, when I modify data...
8
by: Gabe Moothart | last post by:
Hi, I'm writing a windows service which interacts with a separate process. Basically, it calls a process which creates a file, and then my service reads that file. The problem is, the external...
14
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
5
by: Digital Puer | last post by:
I fixed a bug today that went against my intuition. I am on Linux. I had a class that fopen'ed some files. When I called delete on these objects, I expected that the files would be closed...
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
5
by: kailashchandra | last post by:
I am trying to upload a file in php,but it gives me error msg please Help me? My Code is like below:- i have one php file named upload.php and i have another html file named upload.html and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.