DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 13 Aug 2007 15:54:26 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    GaryDean am
          2    (Walter Wang [MSFT])
                 3    GaryDean am
                 4    GaryDean am
                 5    (Walter Wang [MSFT])
          6    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]


Display .DOC file in Varbinary   
I'm storing Images and MSWord doc files in Varbinry columns.  I have no 
problem getting and displaying the images but I'm looking for the right 
approach to allowing the user to download the MSWord doc in the varbinary. 
I've provided download of .doc files from my own directories but never from 
the file system or a varbinary.

Anyone know how to do that?

-- 
Regards,
Gary Blakely
Date:Mon, 13 Aug 2007 15:54:26 -0700   Author:  

RE: Display .DOC file in Varbinary   
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 (wawang@online.microsoft.com, 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.
Date:Tue, 14 Aug 2007 09:10:55 GMT   Author:  

Re: Display .DOC file in Varbinary   
You should be able to use the techniques I've outlined here to dish out the 
docs on demand:
http://dotnetslackers.com/articles/aspnet/FileDenial.aspx

-- 
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net


"GaryDean" <GaryDean@newsgroups.nospam> wrote in message 
news:ebD6nxf3HHA.1208@TK2MSFTNGP05.phx.gbl...

> I'm storing Images and MSWord doc files in Varbinry columns.  I have no 
> problem getting and displaying the images but I'm looking for the right 
> approach to allowing the user to download the MSWord doc in the varbinary. 
> I've provided download of .doc files from my own directories but never 
> from the file system or a varbinary.
>
> Anyone know how to do that?
>
> -- 
> Regards,
> Gary Blakely
>
> 
Date:Mon, 13 Aug 2007 16:08:09 -0700   Author:  

Re: Display .DOC file in Varbinary   
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]""  wrote in message 
news:WGDXPMl3HHA.2340@TK2MSFTNGHUB02.phx.gbl...

> 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 (wawang@online.microsoft.com, 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.
> 
Date:Tue, 14 Aug 2007 10:55:44 -0700   Author:  

Re: Display .DOC file in Varbinary   
Walter: This just in...
I practically solved the problem by response.redirecting to another page 
where the code worked fine in the load event.  so the problem is now only of 
academic interest so you might just want to forget about it.
thanks for the help
Gary

""Walter Wang [MSFT]""  wrote in message 
news:WGDXPMl3HHA.2340@TK2MSFTNGHUB02.phx.gbl...

> 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 (wawang@online.microsoft.com, 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.
> 
Date:Tue, 14 Aug 2007 11:14:38 -0700   Author:  

Re: Display .DOC file in Varbinary   
Thanks Steve for your input.

Hi Gary,

As Steve's article shows, it's important to call Response.Clear() and 
Response.End() at the begin and end; otherwise the downloaded file might 
not have the correct data.

Let me know if you have further questions.


Regards,
Walter Wang (wawang@online.microsoft.com, 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.
Date:Wed, 15 Aug 2007 10:23:46 GMT   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us