473,804 Members | 3,433 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot access file after writing it!

Howdy,

I am using ASP.Net 2.0 and Crystal Reports in VS 2005. I am taking a report,
converting it to PDF then writing it out to a folder. Then I attach this
file to an email and send it off. Once it's sent, I then want to delete the
file from the folder, and here lies the issue. When i try to delete it I get
an error stating the file is being used by another process.

Here's the code to create the file

Dim strStream As New
System.IO.Binar yReader(crRepor t.ExportToStrea m(CrystalDecisi ons.[Shared].ExportFormatTy pe.PortableDocF ormat))

Dim fileName As String = "WO-" & Request("woid") & ".pdf"
Dim fs As FileStream = File.Create("c: \temp\" & fileName,
strStream.BaseS tream.Length)

Dim writer As New IO.BinaryWriter (fs)
writer.Write(st rStream.ReadByt es(strStream.Ba seStream.Length ))
writer.Flush()
writer.Close()

fs.Dispose()
fs.Close()
strStream.Close ()
crReport.Close( )

and to delete I simply

File.Delete(fil ePath)
Thanks a million!
David Lozzi

Jul 10 '07 #1
5 2072
Hi David,
Then I attach this file to an email and send it off.
As suggestion: try to obtain what locks your file (e.g. by using process
explorer http://www.sysinternals.com/ntw2k/fr...procexp.shtml). May be
mailer has not been freeing it.

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
Jul 10 '07 #2
Hi David,

PS. Also it's a good way to use "using statement" for disposable objects
to be sure that object will be freed.

Using cn As Dim fs As FileStream = File.Create
// do something
End Using

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

DLHowdy,
DL>
DLI am using ASP.Net 2.0 and Crystal Reports in VS 2005. I am taking a
DLreport, converting it to PDF then writing it out to a folder. Then I
DLattach this file to an email and send it off. Once it's sent, I then
DLwant to delete the file from the folder, and here lies the issue.
DLWhen i try to delete it I get an error stating the file is being
DLused by another process.
DL>
DLHere's the code to create the file
DL>
DLDim strStream As New
DLSystem.IO.Bin aryReader(crRep ort.ExportToStr eam(CrystalDeci sions.[Sha
DLred].ExportFormatTy pe.PortableDocF ormat))
DL>
DLDim fileName As String = "WO-" & Request("woid") &
DL".pdf"
DLDim fs As FileStream = File.Create("c: \temp\" &
DLfileName,
DLstrStream.Bas eStream.Length)
DLDim writer As New IO.BinaryWriter (fs)
DL>
DLwriter.Write( strStream.ReadB ytes(strStream. BaseStream.Leng th))
DLwriter.Flush( )
DLwriter.Close( )
DLfs.Dispose()
DLfs.Close()
DLstrStream.Clo se()
DLcrReport.Clos e()
DLand to delete I simply
DL>
DLFile.Delete(f ilePath)
DL>
DLThanks a million!
DLDavid Lozzi
Jul 10 '07 #3

"David Lozzi" <dl****@nospam. nospamwrote in message
news:D1******** *************** ***********@mic rosoft.com...
Howdy,

I am using ASP.Net 2.0 and Crystal Reports in VS 2005. I am taking a
report, converting it to PDF then writing it out to a folder. Then I
attach this file to an email and send it off. Once it's sent, I then want
to delete the file from the folder, and here lies the issue. When i try to
delete it I get an error stating the file is being used by another
process.

Here's the code to create the file

Dim strStream As New
System.IO.Binar yReader(crRepor t.ExportToStrea m(CrystalDecisi ons.[Shared].ExportFormatTy pe.PortableDocF ormat))

Dim fileName As String = "WO-" & Request("woid") & ".pdf"
Dim fs As FileStream = File.Create("c: \temp\" & fileName,
strStream.BaseS tream.Length)

Dim writer As New IO.BinaryWriter (fs)
writer.Write(st rStream.ReadByt es(strStream.Ba seStream.Length ))
writer.Flush()
writer.Close()

fs.Dispose()
fs.Close()
strStream.Close ()
crReport.Close( )

and to delete I simply

File.Delete(fil ePath)
Thanks a million!
David Lozzi
In your email sending code call the attachments dispose method

yourMailMessage .attachments.di spose()

Mike
Jul 10 '07 #4
Man, I keep forgetting about that little tool. I hope it's available for
Vista!
"Alex Meleta" <am*****@gmail. comwrote in message
news:15******** *************** ***@msnews.micr osoft.com...
Hi David,
>Then I attach this file to an email and send it off.

As suggestion: try to obtain what locks your file (e.g. by using process
explorer http://www.sysinternals.com/ntw2k/fr...procexp.shtml). May be
mailer has not been freeing it.

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

Jul 10 '07 #5
Can I have your love child? That worked. Another dev and I have been chasing
down the stupid filestream object and what not and it was the stupid
message.... Thank you for your generousity and time!

David Lozzi

"vMike" <Mi************ @5nerrawgenospa m.comwrote in message
news:ZZ******** **********@bign ews8.bellsouth. net...
>
"David Lozzi" <dl****@nospam. nospamwrote in message
news:D1******** *************** ***********@mic rosoft.com...
>Howdy,

I am using ASP.Net 2.0 and Crystal Reports in VS 2005. I am taking a
report, converting it to PDF then writing it out to a folder. Then I
attach this file to an email and send it off. Once it's sent, I then want
to delete the file from the folder, and here lies the issue. When i try
to delete it I get an error stating the file is being used by another
process.

Here's the code to create the file

Dim strStream As New
System.IO.Bina ryReader(crRepo rt.ExportToStre am(CrystalDecis ions.[Shared].ExportFormatTy pe.PortableDocF ormat))

Dim fileName As String = "WO-" & Request("woid") & ".pdf"
Dim fs As FileStream = File.Create("c: \temp\" & fileName,
strStream.Base Stream.Length)

Dim writer As New IO.BinaryWriter (fs)
writer.Write(st rStream.ReadByt es(strStream.Ba seStream.Length ))
writer.Flush()
writer.Close()

fs.Dispose()
fs.Close()
strStream.Close ()
crReport.Close( )

and to delete I simply

File.Delete(fil ePath)
Thanks a million!
David Lozzi
In your email sending code call the attachments dispose method

yourMailMessage .attachments.di spose()

Mike

Jul 10 '07 #6

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

Similar topics

8
5484
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
0
1529
by: Zed | last post by:
I have a problem with .net writing to a remote server that I need to deploy on. The app works fine on my local machine. But when got access to the server I went to VS.NET and tried to create a project the regular way, I got this message "The web was created successfully, but an error occurred when trying to configure the application root for this web. Web projects may not operate correctly without application root. The returned error was:...
0
3042
by: Peter Horwood | last post by:
I am having trouble writing an XML file out on my localhost development machine. I get: Server Error in '/ProblemSolved' Application. ----------------------------------------------------------- --------------------- Access to the path "c:\inetpub\wwwroot\ProblemSolved\XMLData\Products.xml
2
7772
by: Raed Sawalha | last post by:
Hello , I have windows service which do listening to specified directory using FileSystemWatcher , on Created Event and Get all the files in the directory using Directory.GetFiles function then foreach file in the files list and passed the file path to a function to read its content then process it then move it to another directory am reading each file content using StreamReader...ReadToEnd function, all process working fine , That when 50...
0
2527
by: chipotle_pickle | last post by:
You're letting a lot of bad links creep onto that page. Do a Google search for "genesis world energy". The second item found is a broken link to the newsroom. (The third item found explains how the page you are working on is a stock fraud scam.) Bump. "V. Jenks" <spam@scientifik.com> wrote in message news:<033201c32f98$c27cf750$a501280a@phx.gbl>... > I'm using an XmlTextWriter to write an xml file to disk. > No matter what I do with...
3
3807
by: guoqi zheng | last post by:
Dear sir, There is an import tool on my web application, user can upload Ms Access file, the file is saved at a temp folder on the server. After the import is finished, for security reason, I need to delete the imported Ms Access file, however, I always get above error, "The process cannot access the file because it is being used by another process" I did close the datareader and connection object. What else can I do to delete this...
0
3500
by: Sin | last post by:
> Xxxxx : error PRJ0008 : Could not delete file 'd:\xxxxxxx.dll'. > Make sure that the file is not open by another process and is not write-protected. > > LINK : fatal error LNK1168: cannot open ../../Debug/xxxxx.dll for writing > > The file 'xxxxxx.dll' cannot be copied to the run directory. The process cannot > access the file because it is being used by another process. > Could not copy temporary files to the output directory.
6
9291
by: sambuela | last post by:
How can I write message to the file located in the wwwroot directory? It seems that IIS protect these files. Let make me cannot do the I/O writing sucessfully. I try to open file's write privileage by file manager and IIS manager. However, one PC is okay and another PC is not. Any help on this will be greatly appreciated. Regards, --sambuela
5
8728
by: ZWeng | last post by:
I created a windows service using FileSystemWatcher to moniter a folder for file drops. The service uses FileStream and StreamReader to read and process the file. After it is done, the file is copied to a different location and deleted in the original folder. If files coming in in short intervals (under sub-second) on XP OS, there is an error occured occassionally with the follow message: System.IO.IOException: The process cannot...
2
2784
by: Nelly78 | last post by:
Hi All, I have a situtation my application is running on windows 2003 server which is a domain and in web.config <Identity impersonation=true username=ABC\XYZ password=******> what i am doing in the code that i take folder path from user and retrive all file information from that folder and writing to a CSV file which i am creating using StreamWriter.
0
10575
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.