<p>I have stored a txt file as string in a database column. Now on one of my aspx page I have a link...I want to open a txt file when the user clicks on this link. How can i read a file from database. I know how to do this using streamreader for a file stored on the disk.</p>

<p>Thanks</p>

This is going to take some clarification.
If the file is stored as a string in the database, all you have to do is read it into a string and display it in a page.
```
```
public void Page_Load(object sender, EventArgs e)
  var text = (from x in dataContext.MyTextTable where x.Id == someId select x.FileText).FirstOrDefault();

  this.textBox.Text = text;
}
```
```
Okay, here's what you need to do. Pseudocode follows:
Load the string from the database
Use the ToCharArray() method on the string to get an array of chars 
Use the HttpResponse object to Write() the char array to the response stream
Here's some almost-compilable code:
```
```
public void Page_Load(object sender, EventArgs e)
{
  var text = Repository.GetTextFile(this.FileTextBox.Text).ToCharArray();

  Response.Clear();
  Response.AddHeader("Content-Disposition", "attachment; filename=" & this.FileTextBox.Text);
  Response.AddHeader("Content-Length", text.Length.ToString());
  Response.ContentType = "application/octet-stream";
  Response.Write(text, 0, text.length);
  Response.End();
}
```
```
I believe the mime type should be that rather than text/plain as the browser may attempt to open the file rather than saving it as an attachment.