Preferred Language:
Listing 21.9 - SqlVirtualFile.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Hosting;
using System.IO;
using System.Web;
namespace AspNetUnleashed
{
/// <summary>
/// Summary description for SqlVirtualFile
/// </summary>
public class SqlVirtualFile : VirtualFile
{
public SqlVirtualFile(string virtualPath)
: base(virtualPath){}
public override Stream Open()
{
// Get content from database
string content = VirtualFiles.FileContentSelect(this.VirtualPath);
// return results as stream
MemoryStream mem = new MemoryStream();
StreamWriter writer = new StreamWriter(mem);
writer.Write(content);
writer.Flush();
mem.Seek(0, SeekOrigin.Begin);
return mem;
}
public string Content
{
get
{
return VirtualFiles.FileContentSelect(this.VirtualPath);
}
}
}
}
Need ASP.NET and Visual Studio 2008 Training?
- Learn ASP.NET 3.5 from Stephen Walther, author of ASP.NET 3.5 Unleashed.
We've provided ASP.NET training for NASA, Lockheed Martin, the National Science Foundation, Verizon,
Boeing, the US House of Representatives, Kaiser, Petco, Mary Kay, and Microsoft.
Why not your company?
-
Receive a four day, hands-on, intensive workshop.
-
We fly to you, anywhere in the world.
-
We can bring our own laptops.
To learn more, visit the
Superexpert Training website.