URI Formats not supported

 
0
 
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Text; public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) Textbox.Text = "Enter your Name here"; } protected void Button_Click(object sender, EventArgs e) { string Filename = "http://localhost:55688/TextFile.txt";
        if (!File.Exists(Filename))
        {
            StreamWriter txtFile = File.CreateText(Filename);
            txtFile.Close();
            txtFile = File.AppendText(Filename);
            txtFile.WriteLine(Textbox.Text);
            txtFile.Close();
        }
        else
            File.AppendAllText(Filename, Textbox.Text);

        NewName.Text = "Text is saved";
        }
    }

getting error "URI formats are not supported"

 
0
 

File doesn't accept URL's. It needs to be an absolute or relative filepath.

Question Answered as of 1 Year Ago by pritaeas
 
0
 

i have changed it to

    string Filename = "~/textFile.txt";

and now it is saying
'Could not find a part of the path 'C:\Program Files (x86)\IIS Express\~\textFile.txt'

 
0
 

The ~ is not automatically expanded. You can use MapPath()

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: