Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Storing and Retriving any document in SQL Server 2000 using ASP.Net

Reply
Thread Tools

Storing and Retriving any document in SQL Server 2000 using ASP.Net

 
 
Manish Naik
Guest
Posts: n/a
 
      06-28-2004
Hi,

Using ASP.Net, I want to store and retrive documents (Word, excel,
etc) from SQL Server 2000 database. I have tried image type data
field, but could not succed. Can any one help me please.

Regards,

Manish Naik
 
Reply With Quote
 
 
 
 
Edward
Guest
Posts: n/a
 
      06-28-2004
list your code here, maybe we can give the answer to you.

> Hi,
>
> Using ASP.Net, I want to store and retrive documents (Word, excel,
> etc) from SQL Server 2000 database. I have tried image type data
> field, but could not succed. Can any one help me please.
>
> Regards,
>
> Manish Naik



 
Reply With Quote
 
 
 
 
Manish Naik
Guest
Posts: n/a
 
      06-30-2004
"Edward" <> wrote in message news:<eqI#>...
> list your code here, maybe we can give the answer to you.
>
> > Hi,
> >
> > Using ASP.Net, I want to store and retrive documents (Word, excel,
> > etc) from SQL Server 2000 database. I have tried image type data
> > field, but could not succed. Can any one help me please.
> >
> > Regards,
> >
> > Manish Naik



__________________________________________________ ___________________

Hi Edward,

Thank you for your response.

I am sending the code that we tried out at listed below.

Your help is highly appreciated.

Regards,

Manish Naik

__________________________________________________ ________________________

The code below allows the user to save data in the ImageGallery Table
While page loads, if there exists any data in the table it displays it
on the page below file text box control.
Clicking on the image will display the image in new explorer.
If the stored type is other then picture...like word, excel, the it
will not be displyed

Try to save data in ImageGallery tabel by clicking on the browse
button
and selecting the documenet u want to save. then click on the upload
button.
Save all types of document like .jpeg, .txt, .xls etc.

It will display the .jpeg file but will show error for other types.




//########### cOMMENT
THIS IS ASPX PAGE

###################//


<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="WebApplication4.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server"
enctype="multipart/form-data">
<p align="center"><font face="Comic Sans MS" size="7"><strong>
<asp:LinkButton id="LinkButton1" style="Z-INDEX: 101; LEFT:
-8px; POSITION: absolute; TOP: 216px"
runat="server">LinkButton</asp:LinkButton>
My Photo Gallary</strong> </font>
</p>
<p align="center"><input id="UploadImage" type="file"
name="UploadImage" runat="server">&nbsp;
<asp:button id="btnUpload" Runat="server"
Text="Upload"></asp:button></p>
<p align="center"></p>
<p align="center">
<aspataList ID="DataList1" Runat="server"
RepeatDirection="Horizontal" RepeatColumns="2">
<ItemTemplate>
<table>
<tr>
<td height="125px">
<a href='WebForm2.aspx?ID=<%#container.dataitem("Imag eID")
%>&amp;source=DB'
target=_blank ><img
src='WebForm2.aspx?ID=<%#container.dataitem("Image ID")
%>&amp;source=DB&amp;width=125'
border=0> </a>
</td>
</tr>
<tr>
<td>
<a href='WebForm2.aspx?ID=<%#container.dataitem("Imag eID")
%>&amp;source=DB'
target=_blank >
<%# container.dataitem("ImageName") %>
</a>
</td>
</tr>
</table>
</ItemTemplate>
</aspataList>
</p>
</form>
</body>
</HTML>





//####################cOMMENT

cODE BEHIND FILE FOR THE ABOVE ASPX PAGE
###########################3//

Imports System.IO
Imports System.IO.Stream
Imports System.Data.SqlClient

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
Protected WithEvents btnUpload As System.Web.UI.WebControls.Button
Protected WithEvents UploadImage As
System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents DataList1 As
System.Web.UI.WebControls.DataList
Protected WithEvents LinkButton1 As
System.Web.UI.WebControls.LinkButton
Protected WithEvents Calendar1 As
System.Web.UI.WebControls.Calendar

#End Region
Dim pubsConn As SqlConnection = New SqlConnection("Data
Source=mm;Initial Catalog=pubs;uid=sa;pwd=dotnet2;")

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
binddata()
End If

End Sub
Public Sub binddata()
Dim sqlconnect As String
sqlconnect = "initial catalog=pubs;data
source=MM;uid=sa;pwd=dotnet2;"
Dim cn As New SqlConnection(sqlconnect)
Dim sqlcmd As String
sqlcmd = "Select ImageId,ImageName from ImageGallery"
Dim cmd As New SqlCommand(sqlcmd, cn)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable("ImageGallery")
da.Fill(dt)
DataList1.DataSource = dt
DataBind()

End Sub

Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnUpload.Click

If UploadImage.PostedFile Is Nothing Then
Response.Write("No File Upload. <br>")
Return
End If

Dim imagestream As Stream = UploadImage.PostedFile.InputStream

Dim imagelength As Integer =
UploadImage.PostedFile.ContentLength
Dim imagetype As String = UploadImage.PostedFile.ContentType

Dim imagename As String
imagename = Path.GetFileName(UploadImage.PostedFile.FileName)

Dim mstream As New MemoryStream()
Dim imagedata(1024) As Byte
Dim count As Integer = imagedata.Length

count = imagestream.Read(imagedata, 0, imagedata.Length)

Do While count > 0
mstream.Write(imagedata, 0, count)
count = imagestream.Read(imagedata, 0, imagedata.Length)
Loop

Dim sqlcmd As String

sqlcmd = "insert into
ImageGallery(imageName,imageType,imageData)"
sqlcmd &= " values ( @imageName,@imageType,@imageData )"

Dim cmd As New SqlCommand(sqlcmd, pubsConn)
cmd.Parameters.Add("@imageName", imagename)
cmd.Parameters.Add("@imageType", imagetype)
cmd.Parameters.Add("@imageData", mstream.GetBuffer())

pubsConn.Open()
cmd.ExecuteNonQuery()
pubsConn.Close()
DataBind()
End Sub

Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles LinkButton1.Click
Response.Redirect("d:/keyhook.txt")

End Sub
End Class




//###############################################

TABLE IS STORED IN pubs database
table name: ImageGallery



ImageId ---- Numeric --- 9
ImageName ---- varchar --- 255
ImageType ---- varchar --- 255
ImageData ---- Image --- 16







############################////////////
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set the default Codepage when storing .aspx document MichiMichi ASP .Net 1 02-09-2007 07:13 AM
Pie chart: ASP.net 2.0, SQL Server 2000, Excel 2000 C Did ASP .Net 3 06-20-2006 08:35 AM
Uploading Data From MS Acess 2000 ti SQL server 2000 =?Utf-8?B?Z2F1cmF2?= ASP .Net 2 01-09-2006 01:42 PM
? Storing Internal Information In An HTML Document (eg Inside Tags) Alec S. HTML 14 02-04-2005 12:59 AM
Error in COM+ while migrating from 2000 Server to 2000 Advace Server Adhik ASP General 1 09-05-2003 08:55 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57