Reputation: 8734
Here i have code base like this:
class Program
{
static void Main(string[] args)
{
try
{
'String str;
'str = Server.MapPath("/financila_csharp");
StreamReader reader = new StreamReader("selectedmdx.txt");
StreamWriter writer = new StreamWriter("selectedxmlmdx.txt");
string line = reader.ReadLine();
while (line != null)
{
XmlDocument dom = new XmlDocument();
dom.LoadXml("<Result>" + System.Security.SecurityElement.Escape(line) + "</Result>");
writer.WriteLine(dom.DocumentElement.OuterXml);
line = reader.ReadLine();
}
Console.WriteLine("Completed");
reader.Close();
writer.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
In console window it is showing "specified file does not exist", even if I have the "selectedmdx.txt" file in the same project directory.
How can I fix it?
Upvotes: 1
Views: 268
Reputation: 1171
Is the file "selectedmdx.txt" added to your visual studio solution? If yes, select it in solution explore and press F4. In the properties window, set the "Copy to output directory" to 'Copy always' or 'Copy if newer', whichever is more suitable for you. This will copy the file to the output directory from where your code is actually running.
Hope this helps...
Vamyip
Upvotes: 0
Reputation: 7193
I think this is a non web application. so try
str = System.IO.Path.GetFullPath("/financila_csharp");
it will work perfectly
Upvotes: 2
Reputation: 884
Server.MapPath works with web applications not console applications.
Refer to this question for getting the path in a console application.
Upvotes: 0