numten
asked on
Open File in Correct Application - .NET / Blob / Oracle / Datagrid
I was wondering if someone an help me get this solution.
I insert a blob into our oracle 9i database. That's fine, no problems with the insert. Now I want to return the information (file name and blob) and place it into a datagrid. All I want though is for the user to see a list of file names and they can click on a file name and it will open the file up in the correct application (word, excel etc...)
Here is some of what I have. This code is what I'm using to manipulate the datagrid, but it's really wrong. I'm returning two field names from my stored procedure: cmnt_txt (name of the blob file) and the actual blob file.
************************** ********** ********** ********** ******
Private Sub dgappln_attm_ItemDataBound (ByVal sender As Object, ByVal e As System.Web.UI.WebControls. DataGridIt emEventArg s) Handles dgappln_attm.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingIt em Then
Dim HLAttachment As HyperLink = e.Item.Cells(0).FindContro l("HLAttac hment")
HLAttachment.NavigateUrl = e.Item.DataItem("cmnt_txt" ) 'not right. I want it to open not navigate to a url
HLAttachment.Text = e.Item.DataItem("cmnt_txt" ).ToString 'this is the list of file names
End If
End Sub
************************** ********** ********
I'll award extra points for quick response and easy to implement. Please be gentle, I'm a beginner and get lost easy. :)
Thanks! ;)
I insert a blob into our oracle 9i database. That's fine, no problems with the insert. Now I want to return the information (file name and blob) and place it into a datagrid. All I want though is for the user to see a list of file names and they can click on a file name and it will open the file up in the correct application (word, excel etc...)
Here is some of what I have. This code is what I'm using to manipulate the datagrid, but it's really wrong. I'm returning two field names from my stored procedure: cmnt_txt (name of the blob file) and the actual blob file.
**************************
Private Sub dgappln_attm_ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingIt
Dim HLAttachment As HyperLink = e.Item.Cells(0).FindContro
HLAttachment.NavigateUrl = e.Item.DataItem("cmnt_txt"
HLAttachment.Text = e.Item.DataItem("cmnt_txt"
End If
End Sub
**************************
I'll award extra points for quick response and easy to implement. Please be gentle, I'm a beginner and get lost easy. :)
Thanks! ;)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oh whoops didnt see that it was asp.net. actually all you need to do is set the content type and the write the binary to response.
ill post an example when I get to the office in about 45 minutes.
ill post an example when I get to the office in about 45 minutes.
ASKER
I would greatly appreciate that! :) Thanks!
ASKER
I haven't had a chance to try out your suggestion, but I will tomorrow. I did not forget about you and your hard work!
put something along the lines of this in the page load of "File.aspx"
//get the image id from the url
string ImageId = Request.QueryString["FileI
//build our query statement
string sqlText = "SELECT data, contenttype FROM files WHERE pkFileId = " + FileId;
SqlConnection connection = new SqlConnection(ConenctionSt
SqlCommand command = new SqlCommand( sqlText, connection);
//open the database and get a datareader
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if ( dr.Read()) //yup we found our image
{
Response.ContentType = dr["contenttype"].ToString
Response.BinaryWrite( (byte[]) dr["data"] );
}
connection.Close();
then you can put your links to "file.aspx?FileId=5" (or whatever)
You can do this most of the time with your response (just change the content type). If the remote pc knows the content type it can open.
Public Class DocumentRequestHandler
Implements IHttpHandler
'Notice ProcessRequest is the only method
'exposed by the IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements System.Web.IHttpHandler.Pr
Dim strFilename As String
Dim appsrv As New WebService.ASMXFile
'grab filename from end of URL
Dim strArray As String() = Split(context.Request.RawU
strFilename = strArray(UBound(strArray))
strArray.Initialize()
strArray = Split(strFilename, ".")
strFilename = strArray(0)
strArray = Nothing
context.Response.ContentTy
context.Response.BinaryWri
End Sub
'By calling IsReusable, an HTTP factory can query a handler to
'determine whether the same instance can be used to service
'multiple requests
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.Is
Get
Return True
End Get
End Property
End Class
The ContentType will need to be set with the correct MIMEType based on the file extension of the file. You can simply do that with a case statement.
You need to andd the following to the <HTTPHandlers> section of Web.config:
<add verb="*" path="*xdocuments/*" type="YourProjectName.Docu
The url of the document needs to have xdocuments/filenamefromdb for this to work as the HTTPHandler is only invoked to pull the document from the database when it sees xdocuments in the URL.
James :-)