If my path works on local why does it not after deployment to http?

I have a a couple of delete buttons from the frontend which are processed via these functions:

protected void ibDel01_Click(object sender, ImageClickEventArgs e)
        Classes.deleteFile(GridView1, "01", hplCorr01);

    protected void ibDel02_Click(object sender, ImageClickEventArgs e)
        Classes.deleteFile(GridView1, "02", hplCorr02);


The I have main Classes.cs file which defines our deleteFile function:

public static string sDocumentFilePath = "~/Correspondence/";
public static void deleteFile(GridView gv, string sFileNo, HyperLink hpl)
        string sID = gv.SelectedDataKey[0].ToString();
        string sURL = "CorrFile" + sFileNo;
        string sURLdate = "CorrFile" + sFileNo + "Date";
        Classes.deleteFileFromSql(sID, sURL, sURLdate);
        //delete from folder
        string sFile = hpl.NavigateUrl.ToString().Remove(0, 17);

    public static void deleteFileFromSql(string sID, string sURL, string sURLdate)
        SqlDateTime sqldatenull = SqlDateTime.Null;
        string sSql = "UPDATE dbo.tbl_uploads " +
            "SET " + 
                sURL + " = " + sqldatenull + 
                ", " + sURLdate + " = " + sqldatenull +
                    " WHERE fID = " + sID;
        SqlCommand comm = new SqlCommand(sSql);
        comm.Parameters.Add("@ID", SqlDbType.Int).Value = sID;
        if (DBConnect.CmdExecute(comm, sSql)) { } else { }

    public static void deleteFileFromServer(HyperLink hpl)
        string sFile = hpl.NavigateUrl.ToString().Remove(0, 16);
        string sPath = HttpContext.Current.Server.MapPath(Classes.sDocumentFilePath);
        //string sPath = HttpContext.Current.Request.ApplicationPath;
        if (Directory.Exists(sPath))
            File.Delete(sPath + sFile);

As we can see it's simple functionality that deletes (makes data empty on db) data for the specified columns (sURL). Now this works locally (IIS > localhost) but on the live it does not delete and in fact no action happens at all on the frontend nor does data get removed from the db nor does the physical file get removed from the defined directory. Is this a directory definition issue or security issue(application's secure paths)?


The physical path locally: C:\Docs\VS2012\BABYAPP
Virtual local's URL: http:/localhost:0000/babyapp/admin.aspx
Local file uploads location: C:\Docs\VS2012\BABYAPP\Correspondence

The physical path for live: D:\motherapp\babyapp
Virtual live's URL: http://motherapp/babyapp/admin.aspx
Live file uploads location: D:\motherapp\BABYAPP\Correspondence

Any thoughts?


Probably reason

If the path is correct as you say, and works locally then the issue is on permissions.

To been able to delete the file, you must give on the directory/file the permission on the user under witch your pool is running

See here how you can do that: How to set correct file permissions for ASP.NET on IIS

Alternative reason

Other reason that a file can not be deleted is because have been opened by some other program/procedure..

Some comments

The File.Delete Method throw exception if fail to delete the file, so probably the Directory.Exists Method fails also because of permissions, or you have exception that you miss.

from msdn:

If you do not have at a minimum read-only permission to the directory, the Exists method will return false.

Need Your Help

How to process a file returned from JFileChooser in Java

java jbutton actionlistener jfilechooser

I have an application to create graphic representation of data.