Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Unable to delete the file saved on the server.

Unable to delete the file saved on the server.

Scheduled Pinned Locked Moved ASP.NET
helpsysadminsecurityquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MissionSuccess
    wrote on last edited by
    #1

    Respected Gurus I m using following code to import data from an excel file.. It works fine except one problem that whenever i m trying to delete the file which i have saved on the server by using file.delete(strfilename) i left with the error "you do not have permission" I think i have not closed the excel file. how can i close it programmatically so that i can delete it also. Dim strfilename As String ' Check the first open file dialog for a value If Not (Me.File1.PostedFile Is Nothing) Then ' Get a reference to PostedFile object Dim attFile As HttpPostedFile = File1.PostedFile ' Get size of the file Dim attachFileLength As Integer = attFile.ContentLength 'Make sure the size of the file is > 0 If attachFileLength > 0 Then ' Get the file name strfilename = Path.GetFileName(File1.PostedFile.FileName) 'Preceed the file name with "attachments/" so 'the file is saved to our Project's attachments Folder strfilename = "Uploads/" + strfilename 'Save the file on the server File1.PostedFile.SaveAs(Server.MapPath(strfilename)) End If End If Dim strConnectionString As String = String.Empty '---------------------------------------------------------- 'strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Driver=Microsoft Text Driver (*.txt;*.csv);Data Source=" + Server.MapPath(strfilename) + ";Extensions=asc,csv,tab,txt;Persist Security Info=False" '---------------------------------------------------------- strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strfilename) + ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" Dim cnCSV As New OleDbConnection(strConnectionString) cnCSV.Open() Dim cmdSelect As New OleDbCommand("SELECT * FROM [sheet1$]", cnCSV) cmdSelect.CommandType = CommandType.Text Dim daCSV As New OleDbDataAdapter daCSV.SelectCommand = cmdSelect Dim ds As New DataSet daCSV.Fill(ds) after using the dataset. at last i am trying to delete the file. which give me the

    I K 2 Replies Last reply
    0
    • M MissionSuccess

      Respected Gurus I m using following code to import data from an excel file.. It works fine except one problem that whenever i m trying to delete the file which i have saved on the server by using file.delete(strfilename) i left with the error "you do not have permission" I think i have not closed the excel file. how can i close it programmatically so that i can delete it also. Dim strfilename As String ' Check the first open file dialog for a value If Not (Me.File1.PostedFile Is Nothing) Then ' Get a reference to PostedFile object Dim attFile As HttpPostedFile = File1.PostedFile ' Get size of the file Dim attachFileLength As Integer = attFile.ContentLength 'Make sure the size of the file is > 0 If attachFileLength > 0 Then ' Get the file name strfilename = Path.GetFileName(File1.PostedFile.FileName) 'Preceed the file name with "attachments/" so 'the file is saved to our Project's attachments Folder strfilename = "Uploads/" + strfilename 'Save the file on the server File1.PostedFile.SaveAs(Server.MapPath(strfilename)) End If End If Dim strConnectionString As String = String.Empty '---------------------------------------------------------- 'strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Driver=Microsoft Text Driver (*.txt;*.csv);Data Source=" + Server.MapPath(strfilename) + ";Extensions=asc,csv,tab,txt;Persist Security Info=False" '---------------------------------------------------------- strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strfilename) + ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" Dim cnCSV As New OleDbConnection(strConnectionString) cnCSV.Open() Dim cmdSelect As New OleDbCommand("SELECT * FROM [sheet1$]", cnCSV) cmdSelect.CommandType = CommandType.Text Dim daCSV As New OleDbDataAdapter daCSV.SelectCommand = cmdSelect Dim ds As New DataSet daCSV.Fill(ds) after using the dataset. at last i am trying to delete the file. which give me the

      I Offline
      I Offline
      InsDev
      wrote on last edited by
      #2

      please check out your system configuration. have your system has permission to delete any file. could be possible this. Devjit

      1 Reply Last reply
      0
      • M MissionSuccess

        Respected Gurus I m using following code to import data from an excel file.. It works fine except one problem that whenever i m trying to delete the file which i have saved on the server by using file.delete(strfilename) i left with the error "you do not have permission" I think i have not closed the excel file. how can i close it programmatically so that i can delete it also. Dim strfilename As String ' Check the first open file dialog for a value If Not (Me.File1.PostedFile Is Nothing) Then ' Get a reference to PostedFile object Dim attFile As HttpPostedFile = File1.PostedFile ' Get size of the file Dim attachFileLength As Integer = attFile.ContentLength 'Make sure the size of the file is > 0 If attachFileLength > 0 Then ' Get the file name strfilename = Path.GetFileName(File1.PostedFile.FileName) 'Preceed the file name with "attachments/" so 'the file is saved to our Project's attachments Folder strfilename = "Uploads/" + strfilename 'Save the file on the server File1.PostedFile.SaveAs(Server.MapPath(strfilename)) End If End If Dim strConnectionString As String = String.Empty '---------------------------------------------------------- 'strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Driver=Microsoft Text Driver (*.txt;*.csv);Data Source=" + Server.MapPath(strfilename) + ";Extensions=asc,csv,tab,txt;Persist Security Info=False" '---------------------------------------------------------- strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strfilename) + ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" Dim cnCSV As New OleDbConnection(strConnectionString) cnCSV.Open() Dim cmdSelect As New OleDbCommand("SELECT * FROM [sheet1$]", cnCSV) cmdSelect.CommandType = CommandType.Text Dim daCSV As New OleDbDataAdapter daCSV.SelectCommand = cmdSelect Dim ds As New DataSet daCSV.Fill(ds) after using the dataset. at last i am trying to delete the file. which give me the

        K Offline
        K Offline
        kubben
        wrote on last edited by
        #3

        Your web site runs under an app pool. That app pool has an identity. That user that the app pool is running as needs to be able to delete files in the correct directory. Often it makes sense to create a new app pool for each new web application. Then you can create a network user for that specific application and give that user the correct rights. Ben

        M 1 Reply Last reply
        0
        • K kubben

          Your web site runs under an app pool. That app pool has an identity. That user that the app pool is running as needs to be able to delete files in the correct directory. Often it makes sense to create a new app pool for each new web application. Then you can create a network user for that specific application and give that user the correct rights. Ben

          M Offline
          M Offline
          MissionSuccess
          wrote on last edited by
          #4

          Thanks sir resolve it was a permission issue. given the rights and now working smoothly.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups