Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 25th, 2005, 01:44 AM
Registered User
 
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to dungerdanish Send a message via Yahoo to dungerdanish
Default cannot delete file from server

hi every one.

I've run into a bit of a problem, i have looked o the net but I havent come up with a solution yet

we upload the file, save it as a temp file on server , read data from it, update the database and close the filestream and then try to delete it but sometimes, it gives this weird error that its still in use... when debugging through the code 'slowwly' this error is not encountered but even going fast in debugging mode this eception occurs again, here's the code

///
...
fileStream.DiscardBufferedData()
        fileStream.Close()
        fileStream = Nothing
        binddgErrors()
        If Not errorIndicator Then displayRecordCount(validRecordCount, invalidRecordCount, duplicateRecordCount)
        initDeleteOperation()
...
///


Private Sub initDeleteOperation()
        If Not File1.PostedFile Is Nothing Then
            If CheckFileType() Then
                If File1.PostedFile.ContentType = "text/plain" Then
                    If File.Exists(Server.MapPath("UploadedFile\" & Session.SessionID & ".txt")) Then DeleteFile(("UploadedFile\" & Session.SessionID & ".txt"))
                Else
                    If File.Exists(Server.MapPath("UploadedFile\" & Session.SessionID & ".xls")) Then DeleteFile(("UploadedFile\" & Session.SessionID & ".xls"))
                End If
            End If
        End If
    End Sub




Private Sub DeleteFile(ByVal filename As String)
        Dim f As File
        f.Delete(Server.MapPath(filename))

    End Sub


I even tried have the buffer flushed and assigning teh reference to null, still it says that the file is in use on the delete method....

anyone knows a work around? (sure I could look up any text files in the folder at the start of the procedure and delete them, but I still want to know how to do it this way)

thanx

 
Old May 25th, 2005, 02:10 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Is there a need to save the file to disk at all? When you upload a file you get the filestream as part of the request information (accessible on the file input control). Can you do what you need with that stream instead of saving to disk then opening the file? Then you won't encounter the problem at all.

-Peter
 
Old May 26th, 2005, 12:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

u r not have to make it difficult dear!!
u could use
Code:
SaveAs
Method of
Code:
System.Web.HttpPostedFile
HTH.

Always:),
Hovik Melkomian.
 
Old May 26th, 2005, 11:27 PM
Registered User
 
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to dungerdanish Send a message via Yahoo to dungerdanish
Default

Thanx peter, I'll attempt that... and I'll post the results later here


 
Old May 30th, 2005, 03:39 AM
Authorized User
 
Join Date: Jun 2004
Posts: 54
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello there,

Can't anybody give a solution to my post.
http://p2p.wrox.com/topic.asp?TOPIC_ID=30998

Vinod Pawar
India
The Following User Says Thank You to vinod_pawar1 For This Useful Post:





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot delete file from Remote server. snowbydave1 Pro PHP 0 March 7th, 2007 02:57 AM
Cannot delete file from Remote server. snowbydave1 PHP Databases 0 March 7th, 2007 02:54 AM
Cannot delete file from Remote server. snowbydave1 PHP FAQs 0 March 7th, 2007 02:52 AM
Delete a file on the server zaeem Classic ASP Databases 4 April 26th, 2005 10:00 PM
Delete a file on the server zaeem Classic ASP Basics 0 April 20th, 2005 10:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.