How to delete a file in web server in ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davidson1
    New Member
    • Feb 2008
    • 144

    How to delete a file in web server in ASP.NET

    Posted Date :- 17 feb 2008

    Hello to everybody,
    I am very thankful to "the scripts" contributors. Their answers are really useful to me.

    Now i have a Question

    I am storing a image in webserver normally in c:\inetpub\wwwr oot\picture
    folder

    In case i know how to insert a image in webser.. by the following code.

    If Not (myfile.PostedF ile Is Nothing) Then

    Dim intFileNameLeng th As Integer
    Dim strFileNamePath As String
    Dim strFileNameOnly As String

    'Logic to find the FileName (excluding the path)
    strFileNamePath = myfile.PostedFi le.FileName
    intFileNameLeng th = InStr(1, StrReverse(strF ileNamePath), "\")
    strFileNameOnly = Mid(strFileName Path, (Len(strFileNam ePath) - intFileNameLeng th) + 2)
    If strFileNameOnly = "" Then
    Lab.Text = "You Must Choose a Picture"
    Exit Sub
    End If
    myfile.PostedFi le.SaveAs("c:\i netpub\wwwroot\ Picture\" & strFileNameOnly )
    path = "http://localhost/Picture/" & strFileNameOnly


    End If






    But I dont know how to delete a image in the webserver,
    if anybody Knows Pl reply to me...

    Waiting for Ur Reply.......... ..............



    Davidson
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    You can use the following method to delete the files on the web server :

    File.Delete("di rectory path")

    Originally posted by davidson1
    Posted Date :- 17 feb 2008

    Hello to everybody,
    I am very thankful to "the scripts" contributors. Their answers are really useful to me.

    Now i have a Question

    I am storing a image in webserver normally in c:\inetpub\wwwr oot\picture
    folder

    In case i know how to insert a image in webser.. by the following code.

    If Not (myfile.PostedF ile Is Nothing) Then

    Dim intFileNameLeng th As Integer
    Dim strFileNamePath As String
    Dim strFileNameOnly As String

    'Logic to find the FileName (excluding the path)
    strFileNamePath = myfile.PostedFi le.FileName
    intFileNameLeng th = InStr(1, StrReverse(strF ileNamePath), "\")
    strFileNameOnly = Mid(strFileName Path, (Len(strFileNam ePath) - intFileNameLeng th) + 2)
    If strFileNameOnly = "" Then
    Lab.Text = "You Must Choose a Picture"
    Exit Sub
    End If
    myfile.PostedFi le.SaveAs("c:\i netpub\wwwroot\ Picture\" & strFileNameOnly )
    path = "http://localhost/Picture/" & strFileNameOnly


    End If






    But I dont know how to delete a image in the webserver,
    if anybody Knows Pl reply to me...

    Waiting for Ur Reply.......... ..............



    Davidson

    Comment

    • davidson1
      New Member
      • Feb 2008
      • 144

      #3
      Hai thank U,

      when i give file.Delete it is showing error , can U give some detailed code, so that i can try...

      Thank U......

      Waiting for Ur Reply....

      Posted Date :- 18 Feb 2008

      Comment

      • davidson1
        New Member
        • Feb 2008
        • 144

        #4
        Thank U

        System.IO.File. Delete("path")

        worked for me...........

        Thanks......... .....

        Comment

        Working...