0

I have written a method to save xml file to my project.and I run that method automatically in specific time period(once a day(at 3.00 pm)), same file. but we have to include that file to the project manually.What I want is before xml file save, look if it is exists. if it is exists delete it and save the new one and include it. this is my code.

this is how I save ....

  public void sendValue()
        {
            string wbserviceUrl = "https://someurl.ashx";
            WebClient clientOne = new WebClient();
            string result = clientOne.DownloadString(wbserviceUrl);

            XmlDocument cruisexmlDocument = new XmlDocument();

            cruisexmlDocument.LoadXml(result);
            cruisexmlDocument.Save("D:/projects/booksmal/XmlFiles/Cruisedata/product.xml");

        }

In here I want to check,

  • 1 -check if the file("product.xml") is exist.
  • 2 -if it is exists then delete it and save the new ("product.xml")
  • 3 -then include that file to the project(is this happen automatically when site host)

(Note: save the file is work fine)

4
  • File.Exists() and File.Delete() Commented Dec 9, 2015 at 11:14
  • How to use it , I'm new to MVC Commented Dec 9, 2015 at 11:15
  • it gives this error, I'm using this in MVC Error 103 'System.Web.Mvc.Controller.File(string, string, string)' is a 'method', which is not valid in the given context Commented Dec 9, 2015 at 11:16
  • check the existing is success. Used System.IO.File instead of File now how to include saved automatically to the project, without doing it manually Commented Dec 9, 2015 at 11:31

1 Answer 1

1
string path = Server.MapPath("~/XmlFiles/Cruisedata/product.xml");
if (System.IO.File.Exists(path))
{
   System.IO.File.Delete(path);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.