473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
Nov 18 '05 #1
2 2450
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

Nov 18 '05 #2
"Edward" <zi***@citiz.net> wrote in message news:<eq**************@TK2MSFTNGP12.phx.gbl>...
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">
<asp:DataList 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>
</asp:DataList>
</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



############################////////////
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Horowitz | last post by:
Hi folks, I want to be able to store and retrieve UNSAVED Word documents as BLOBs. I got all the info for storing them if they're already saved on the file system. But what if they're not...
7
by: Dave | last post by:
I have a system that basically stores a database within a database (I'm sure lots have you have done this before in some form or another). At the end of the day, I'm storing the actual data...
5
by: Don Vaillancourt | last post by:
I'm building a system when one can upload a document to the website. I will be storing the document on the hard-drive for quick/easy access, but I was also thinking of storing it in an existing...
3
by: Ringo Langly | last post by:
Hi folks, Is it possible to store Binary Files in MS SQL 2000 ??? Say I have a 100K PDF or a 150K word document. Is it possible to store this in a field in MS SQL and pull it out somehow? ...
6
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to...
7
by: Tzanko | last post by:
As we all know, there is a 8060 bytes size limit on SQL Server rows. I have a table which requires a number of text fields (5 or 6). Each of these text fields should support a max of 4000...
2
by: balakrishnan.dinesh | last post by:
Hi frnds, Im having a problem with retriving "\" backslash , In my javascript client side page , ill get the response from the server side , the response will contain some url like...
2
by: Sourabh Agrawal | last post by:
Dear All, Pls give some idea about storing and retriving images in a MS- Access database using VB6. Thanks Sourabh
4
by: lorirobn | last post by:
Hi, I need to add photos to my database. Back End is on MS SQL Server (I believe 2000), and Front End is on MS Access. I have read about storing the photos as BLOBS, but I am not sure how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.