none
How to Delete XML File from Remote server at runtime

    Question

  •  Hi Team,

    I have simple project in Asp.net  reading XML file on remote server.

    I upload xml file using upload control , which will be saved on server database . for next file reading I want to delete previous uploaded file .

    ===================================

    I have used this code :

    protected void Button1_Click(object sender, EventArgs e)
        {

            if (FileUpload1.HasFile)
           {
                Label32.Visible = false;
                FileUpload1.SaveAs(Server.MapPath("~/") + FileUpload1.FileName);
            }
            if (FileUpload1.HasFile)
            {
                Panel1.Visible = true;
                Panel2.Visible = true;

                FileUpload1.Visible = false;
                Button1.Visible = false;
                XmlReader xmlRdr = XmlReader.Create(Server.MapPath("~/") + FileUpload1.FileName);
               

                while (xmlRdr.Read())
                {
                    if (xmlRdr.Name == "CompanyName")
                    {
                        Label13.Text = (Label13.Text == string.Empty) ? xmlRdr.ReadString() : Label13.Text;

                    }

    ======================================================

    Please tell me how to delete it ? ?

    -Many Thanks

    :omshree


    Saturday, November 16, 2013 12:01 PM

Answers

  • I think that you are in the Wrong forum.

    as I see it you want to cleanup after the upload and parsing is done.

    then after finished parsing and releasing the xml objects you'll need to do

    if (File.Exists(Server.MapPath("~/") + FileUpload1.FileName))
    {
    File.Delete(Server.MapPath("~/") + FileUpload1.FileName);
    }

    exists

    http://msdn.microsoft.com/en-us/library/system.io.file.exists(v=vs.110).aspx

    delete

    http://msdn.microsoft.com/en-us/library/system.io.file.delete(v=vs.110).aspx

    Sunday, November 17, 2013 11:38 AM
  • Hi tetitu

    This is the same explanation as RSingh wrote in his first response, But it is not sure to be correct!

     read my response above :-) Using sql 2012 you can run this code and insert a upload a file directly to the SQL Server database. the database is like black box and the SQL Server can manage the data as it was on a regular folder. This is why i asked him for more information :-)

    * RSingh & you probably post the solution that fit to his problem, and he is not using the database probably (this is my guess too... but this is only Assumption). it is not sure to be the case! maybe he is using the database (SQL 2012 FILESTREAM) and his question fit to this forum :-) in any case the solution you post probably fit as RSingh's sulotion too.

    ** i just comment on the "Wrong forum" as i comment on "Your C# code does not upload data in the SQL Server" before :-)


    [Personal Site] [Blog] [Facebook]signature

    Monday, November 18, 2013 10:16 AM

All replies