Kevin
Kevin

Reputation: 69

Creating file on server in asp.net project

I want to create file and this file must create in folder App_Data in my project.

How I can do it?

 FileInfo MyFile = new FileInfo("~\\App_Data\\asd.txt");
            if (MyFile.Exists == false)
            {
                FileStream fs = MyFile.Create();
                fs.Close();
            }

I get this error

Could not find part of the path "C:\Program Files (x86)\IIS Express\~\asd.txt".

Upvotes: 0

Views: 4195

Answers (1)

Devesh
Devesh

Reputation: 4550

Try to use this code

FileInfo MyFile = new FileInfo(Server.MapPath("~\\App_Data\\asd.txt"));

Upvotes: 1

Related Questions