Accessing File from the Server

I developed a WCF service and consuming to another application. In that service i have an xml file.

What is the way to access the file.

I have used the following code:

public string InsertData(string Name, string Email, string Message)
{
    string file = System.Web.Hosting.HostingEnvironment.MapPath("DataFile.xml");
    DataTable dtEmployee = ReadXML(file);
    // adding Employee Object values to datarow.
    DataRow dr = dtEmployee.NewRow();
    dr["Name"] = Name;
    dr["Email"] = Email;
    dr["Message"] = Message;
    dtEmployee.Rows.Add(dr);
    dtEmployee.WriteXml(file);
    return "Success";
}

File exists on the same project. How can i access that file. You can get the idea from the following screenshot:

Currently the file is getting null.

Please help. I searched a lot but still not getting the value..

Answers


you can use the below menioned code.

Add method name in your interface of service like

    [OperationContract]
    string GetXmlstring();

Implemetation of method look like

public string GetXmlstring()
    {
        var fileName = AppDomain.CurrentDomain.BaseDirectory;
        StreamReader reader = new StreamReader(fileName+"\\DataFile.xml");
        return reader.ReadToEnd();
    }

call that method like

        ServiceReference1.Service1Client ss = new ServiceReference1.Service1Client();
        var xmlstring=ss.GetXdoc();

Now xmlstring contain the xml string.


Need Your Help

What are the best practices for designing a RESTful public API on Rails?

ruby-on-rails api rest

Rails comes with RESTful resources out of the box, but do you use those for your actual public API? If so, how would you accomplish versioning of your API i.e. example.com/api/v2/foo/bar?

Best way to redirect non-www to www?

url redirect dns http-status-code-301 no-www

What would be the best way to redirect my non-www urls to www url in my site.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.