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);
//Classes.deleteFileFromServer(hpl);
}
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)?
Structure:
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?