Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

I am unable to get correct file path to delete a file from the server.
I am able to delete the file when i run my code in localhost also am able to delete file and i change the connection string to live connection string .

I want to delete a file which has been hosted live in server using ftp .using asp.net code
The file has delete permission.

The code for deleting

C#
try
{

    FileInfo TheFile = new FileInfo(Server.MapPath(TextBox2.Text));



    if (TheFile.Exists)
    {
        File.Delete(Server.MapPath(TextBox2.Text));
        Response.Write("success");
    }
    else
    {
        throw new FileNotFoundException();
    }
}

catch (FileNotFoundException ex)
{
    //  lblStatus.Text += ex.Message;
    Response.Write("              ");
    Response.Write(ex.Message);
}
catch (Exception ex)
{
    Response.Write("         ");
    Response.Write(ex.Message);
}
Posted
Comments
Sergey Alexandrovich Kryukov 6-Sep-13 1:21am    
Who knows what's entered in TextBox2? It could be invalid path...
—SA
aassaahh 6-Sep-13 1:22am    
but in local it is working
Sergey Alexandrovich Kryukov 6-Sep-13 1:24am    
No wonder. This is the usual thing. Sample of data, please. What's the entered path and actual path the file on server...
—SA
Dholakiya Ankit 10-Sep-13 0:50am    
What u r entring in textbox?
Member 10086668 12-Sep-13 18:48pm    
Is the file in a subdirectory of your ASP.NET project?

If it is NOT, then just remove the Server.MapPath() method call and use the raw URL provided.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900