Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Cannot access file after writing it!

Reply
Thread Tools

Cannot access file after writing it!

 
 
David Lozzi
Guest
Posts: n/a
 
      07-10-2007
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

 
Reply With Quote
 
 
 
 
Alex Meleta
Guest
Posts: n/a
 
      07-10-2007
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


 
Reply With Quote
 
 
 
 
Alex Meleta
Guest
Posts: n/a
 
      07-10-2007
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



DL> Howdy,
DL>
DL> I am using ASP.Net 2.0 and Crystal Reports in VS 2005. I am taking a
DL> report, converting it to PDF then writing it out to a folder. Then I
DL> attach this file to an email and send it off. Once it's sent, I then
DL> want to delete the file from the folder, and here lies the issue.
DL> When i try to delete it I get an error stating the file is being
DL> used by another process.
DL>
DL> Here's the code to create the file
DL>
DL> Dim strStream As New
DL> System.IO.BinaryReader(crReport.ExportToStream(Cry stalDecisions.[Sha
DL> red].ExportFormatType.PortableDocFormat))
DL>
DL> Dim fileName As String = "WO-" & Request("woid") &
DL> ".pdf"
DL> Dim fs As FileStream = File.Create("c:\temp\" &
DL> fileName,
DL> strStream.BaseStream.Length)
DL> Dim writer As New IO.BinaryWriter(fs)
DL>
DL> writer.Write(strStream.ReadBytes(strStream.BaseStr eam.Length))
DL> writer.Flush()
DL> writer.Close()
DL> fs.Dispose()
DL> fs.Close()
DL> strStream.Close()
DL> crReport.Close()
DL> and to delete I simply
DL>
DL> File.Delete(filePath)
DL>
DL> Thanks a million!
DL> David Lozz


 
Reply With Quote
 
vMike
Guest
Posts: n/a
 
      07-10-2007

"David Lozzi" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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


 
Reply With Quote
 
David Lozzi
Guest
Posts: n/a
 
      07-10-2007
Man, I keep forgetting about that little tool. I hope it's available for
Vista!


"Alex Meleta" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) .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
>
>


 
Reply With Quote
 
David Lozzi
Guest
Posts: n/a
 
      07-10-2007
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" <(E-Mail Removed)> wrote in message
news:ZZNki.20972$(E-Mail Removed).. .
>
> "David Lozzi" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
>> 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
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 2 11-29-2006 04:30 AM
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 0 11-28-2006 09:13 AM
Cannot Copy Assembly <MyAssembly> The Process Cannot Access The File Because It Is Being Used By Another Process Ram ASP .Net 2 06-30-2005 11:30 AM
Cannot delete file from webserver...... process cannot access style error news.microsoft.com ASP .Net 4 01-10-2005 06:07 AM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM



Advertisments