Query for the filename in the Leafname column of AllDocs table and the get the Id of that Row, then update the id in the following code and execute the same. File is in your hands!!!
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.Sql;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlBlob2File();
}
public void SqlBlob2File()
{
try
{
int PictureCol = 0; // the column # of the BLOB field
SqlConnection cn = new SqlConnection("server=vbassql01i\\bassql01in1;integrated security=yes;database=IE_30_06_2010");
SqlCommand cmd = new SqlCommand("SELECT [Content] FROM AllDocStreams WHERE (Id = '5bf23867-98dc-4481-96bc-b568d2209008')", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
Byte[] b = new Byte[(dr.GetBytes(PictureCol, 0, null, 0, int.MaxValue))];
dr.GetBytes(PictureCol, 0, b, 0, b.Length);
dr.Close();
cn.Close();
System.IO.FileStream fs =
new System.IO.FileStream("c:\\02 ATT Invoices.xls", System.IO.FileMode.Create, System.IO.FileAccess.Write);
fs.Write(b, 0, b.Length);
fs.Close();
Response.Write("Image written to file successfully");
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
}
}
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.Sql;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlBlob2File();
}
public void SqlBlob2File()
{
try
{
int PictureCol = 0; // the column # of the BLOB field
SqlConnection cn = new SqlConnection("server=vbassql01i\\bassql01in1;integrated security=yes;database=IE_30_06_2010");
SqlCommand cmd = new SqlCommand("SELECT [Content] FROM AllDocStreams WHERE (Id = '5bf23867-98dc-4481-96bc-b568d2209008')", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
Byte[] b = new Byte[(dr.GetBytes(PictureCol, 0, null, 0, int.MaxValue))];
dr.GetBytes(PictureCol, 0, b, 0, b.Length);
dr.Close();
cn.Close();
System.IO.FileStream fs =
new System.IO.FileStream("c:\\02 ATT Invoices.xls", System.IO.FileMode.Create, System.IO.FileAccess.Write);
fs.Write(b, 0, b.Length);
fs.Close();
Response.Write("Image written to file successfully");
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
}
}
Comments
Post a Comment