[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

save file in asp.net using c#.net

hello,

i want to know that i want to know that i have text in label then i want to write in file and save in asp.net webapplication and also give the user option to download this file .. both those are done on the button click .. thanks..

please write the code and give me the working code.. because i try most but no code are working..

Thanks in advance..
0
AVARICESOFT
Asked:
AVARICESOFT
1 Solution
 
Miguel OzSoftware EngineerCommented:
Check this link:
http://www.aspnettutorials.com/tutorials/file/rw-file-aspnet2-csharp.aspx
buttonSave_Click contains the code for saving the file.

http://www.aspnettutorials.com/tutorials/file/fileupload-csharp.aspx
it is multi file upload but the code is the same for simple upload.
0
 
AVARICESOFTAuthor Commented:
kindly send me the code. . !!
0
 
Miguel OzSoftware EngineerCommented:
From first link:
//
//Asp must contain two labels : textboxPath for filename and textBoxContents for the file contents
//code behind
protected void buttonSave_Click(object sender, EventArgs e)
{

DirectoryInfo Folder = new DirectoryInfo(textboxPath.Text);
if (Folder.Exists)
{

if (textboxName.Text != string.Empty)
{

string FilePathSave = Folder.ToString() + textboxName.Text;

File.WriteAllText(FilePathSave, textBoxContents.Text);
}
else
{

Response.Write("<script language='javascript'>window.alert('Please enter file name');</script>");
}
}
else
{
Response.Write("<script language='javascript'>window.alert('Folder not found');</script>");
}
}
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now