Walter:
the example at kb/326502 works great for downloading a .doc file from a
varbinary with a word document in it. However, when I convert the same code
to c# and use it in my project I get an I.E. error that says:
"the data necessary to complete this operation is not yet available" ??
But the "myData" variable contains exactly the same contents in both cases.
I tried Response.ClearContent() and Response.ClearHeaders() but that made no
difference. In my real project the page is more complex than in the
example.
I pasted the two code snippets below but I don't think it matters since the
stream that I am writing is identical down to the byte.
Thanks,
Gary
Below is the vb code from the example that
works..............................................................
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim con As New SqlConnection("Data Source=(local);Initial
Catalog=PTPEmployment;Integrated Security=True")
Dim da As New SqlDataAdapter("Select * From resumes where
candidateid = 'fred'", con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
con.Open()
da.Fill(ds, "resumes")
Dim myRow As DataRow
myRow = ds.Tables("resumes").Rows(0)
Dim MyData() As Byte
MyData = myRow("resumeblob")
Response.Buffer = True
Response.ContentType = "application/msword"
Response.BinaryWrite(MyData)
MyCB = Nothing
ds = Nothing
da = Nothing
con.Close()
con = Nothing
End Sub
Below is my C# Code that gets the browser
error.................................................................................
protected void btnGetResume_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new
SqlConnection((string)HttpContext.Current.Session["PTPConnectionString"]))
{
conn.Open();
string mySQL = "Select * From resumes where candidateid = '" +
(string)Session["candidateid"] + "'";
SqlDataAdapter da = new SqlDataAdapter(mySQL, conn);
SqlCommandBuilder MyCB = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "resumes");
DataRow myRow;
myRow = ds.Tables["resumes"].Rows[0];
byte[] MyData = null;
MyData = (byte[])myRow["resumeblob"];
Response.Buffer = true;
Response.ContentType = "application/msword";
Response.BinaryWrite(MyData);
MyCB = null;
ds = null;
da = null;
conn.Close();
}
}
--
"Walter Wang [MSFT]" said:
Hi Gary,
I hope I haven't misunderstood your question: I think for a msword
document
from the file system or from varbinary column, you just read them into a
binary byte array and use Response.BinaryWrite to write to response
stream.
The only thing different from writing an image is the ContentType and
Content-Disposition header:
Response.AddHeader("Content-Disposition", "attachment;filename=blob.doc")
Response.ContentType = "application/msword"
Please refer to following KB for more info:
#HOW TO: Read and Write BLOB Data by Using ADO.NET Through ASP.NET
http://support.microsoft.com/kb/326502
Regards,
Walter Wang (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.