473,473 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Create 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.BinaryReader(crReport.ExportToStream(Cry stalDecisions.[Shared].ExportFormatType.PortableDocFormat))

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

Dim writer As New IO.BinaryWriter(fs)
writer.Write(strStream.ReadBytes(strStream.BaseStr eam.Length))
writer.Flush()
writer.Close()

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

and to delete I simply

File.Delete(filePath)
Thanks a million!
David Lozzi

Jul 10 '07 #1
5 2056
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.BinaryReader(crReport.ExportToStream(C rystalDecisions.[Sha
DLred].ExportFormatType.PortableDocFormat))
DL>
DLDim fileName As String = "WO-" & Request("woid") &
DL".pdf"
DLDim fs As FileStream = File.Create("c:\temp\" &
DLfileName,
DLstrStream.BaseStream.Length)
DLDim writer As New IO.BinaryWriter(fs)
DL>
DLwriter.Write(strStream.ReadBytes(strStream.BaseS tream.Length))
DLwriter.Flush()
DLwriter.Close()
DLfs.Dispose()
DLfs.Close()
DLstrStream.Close()
DLcrReport.Close()
DLand to delete I simply
DL>
DLFile.Delete(filePath)
DL>
DLThanks a million!
DLDavid Lozzi
Jul 10 '07 #3

"David Lozzi" <dl****@nospam.nospamwrote in message
news:D1**********************************@microsof t.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.BinaryReader(crReport.ExportToStream(Cry stalDecisions.[Shared].ExportFormatType.PortableDocFormat))

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

Dim writer As New IO.BinaryWriter(fs)
writer.Write(strStream.ReadBytes(strStream.BaseStr eam.Length))
writer.Flush()
writer.Close()

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

and to delete I simply

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

yourMailMessage.attachments.dispose()

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.microsoft .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************@5nerrawgenospam.comwrote in message
news:ZZ******************@bignews8.bellsouth.net.. .
>
"David Lozzi" <dl****@nospam.nospamwrote in message
news:D1**********************************@microsof t.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.BinaryReader(crReport.ExportToStream(Cr ystalDecisions.[Shared].ExportFormatType.PortableDocFormat))

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

Dim writer As New IO.BinaryWriter(fs)
writer.Write(strStream.ReadBytes(strStream.BaseStr eam.Length))
writer.Flush()
writer.Close()

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

and to delete I simply

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

yourMailMessage.attachments.dispose()

Mike

Jul 10 '07 #6

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

Similar topics

8
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 -------------------------------------------------------------------------------- ...
0
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...
0
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. -----------------------------------------------------------...
2
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...
0
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...
3
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...
0
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...
6
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...
5
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...
2
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.