thanks every one for there comments and help,
i have found the soultion which i am posting here for othere pplz
refrence
aspx.code
<asp:Label ID="Label2" runat="server" Text="Title"></asp:Label>
<asp:Label ID="Label1" runat="server" Text="Label"></
asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Image"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="upload" runat="server" Text="Upload"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [DOCID], [FileName], [FileType],
[SavedFile] FROM [DOCSAVE]">
</asp:SqlDataSource>
</div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="DOCID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="DOCID" HeaderText="DOCID"
InsertVisible="False" ReadOnly="True"
SortExpression="DOCID" />
<asp:BoundField DataField="FileName"
HeaderText="FileName" SortExpression="FileName" />
<asp:BoundField DataField="FileType"
HeaderText="FileType" SortExpression="FileType" />
</Columns>
</asp:GridView>
-
*******************************************************************************
code behind
-
*******************************************************************************
Protected Sub Upload_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Upload.Click
Dim fileUpload1 As FileUpload = CType(Me.FindControl
("fileUpload1"), FileUpload)
'Make sure a file has been successfully uploaded
If fileUpload1.PostedFile Is Nothing OrElse
String.IsNullOrEmpty(fileUpload1.PostedFile.FileName) OrElse
fileUpload1.PostedFile.InputStream Is Nothing Then
Label1.Text = "Please Upload Valid picture file"
Exit Sub
End If
'Make sure we are dealing with a JPG or GIF file
Dim extension As String = System.IO.Path.GetExtension
(fileUpload1.PostedFile.FileName).ToLower()
Dim MIMEType As String = Nothing
Select Case extension
Case ".gif"
MIMEType = "image/gif"
Case ".jpg", ".jpeg", ".jpe"
MIMEType = "image/jpeg"
Case ".png"
MIMEType = "image/png"
Case ".pdf"
MIMEType = "pdf"
Case ".doc"
MIMEType = "doc"
Case ".xls"
MIMEType = "xls"
Case Else
'Invalid file type uploaded
Label1.Text = "Not a Valid file format"
Exit Sub
End Select
'Connect to the database and insert a new record into Products
Using myConnection As New SqlConnection
(ConfigurationManager.ConnectionStrings
("NorthwindConnectionString").ConnectionString)
Const SQL As String = "insert into docsave
(FileName,FileType,SavedFile) VALUES (@Title, @MIMEType, @ImageData)"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@Title",
TextBox1.Text.Trim())
myCommand.Parameters.AddWithValue("@MIMEType", MIMEType)
'Load FileUpload's InputStream into Byte array
Dim imageBytes(fileUpload1.PostedFile.InputStream.Length)
As Byte
fileUpload1.PostedFile.InputStream.Read(imageBytes, 0,
imageBytes.Length)
myCommand.Parameters.AddWithValue("@ImageData",
imageBytes)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Using
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
GridView1.SelectedIndexChanged
Dim strExtenstion As String = "extension of retrieved file"
Dim bytFile As Byte()
Dim strSql As String = "select * from docsave where docid = 3"
Dim myReader As SqlDataReader
Dim myConnection As New SqlConnection
(ConfigurationManager.ConnectionStrings
("NorthwindConnectionString").ConnectionString)
Dim myCommand As New SqlCommand(strSql, myConnection)
myConnection.Open()
myReader = myCommand.ExecuteReader
strExtenstion = ".doc"
' bytFile = myReader("savedfile")
Response.Clear()
Response.Buffer = True
If myReader.Read Then
If (strExtenstion = ".doc" Or strExtenstion = ".docx")
Then
Response.ContentType = "application/vnd.ms-word"
Response.AddHeader("content-disposition",
"attachment;filename=" & myReader("filename") & ".doc")
ElseIf (strExtenstion = ".xls" Or strExtenstion = ".xlsx")
Then
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition",
"attachment;filename=Tr.xls")
ElseIf (strExtenstion = ".pdf") Then
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition",
"attachment;filename=Tr.pdf")
End If
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.Private)
' If you write,
'Response.Write(bytFile1);
' then you will get only 13 byte in bytFile.
Response.BinaryWrite(myReader("savedfile"))
Response.End()
End If
myConnection.Close()
End Sub
On Feb 27, 10:11 am, Cerebrus <[email protected]> wrote:
> And I would have appreciated a well worded, detailed question that
> didn't keep the rest of us guessing about the problem.
>
> On Feb 26, 10:16 pm, tahir rameez <[email protected]> wrote:
>
>
>
> > i would have really appreciated if you answered my question rather
> > then criticizing me.- Hide quoted text -
>
> - Show quoted text -