Döküman yönetimi access database inde file upload and view as binary - Papatyam Forum

Papatyam Forum

Go Back   Papatyam Forum > ..::.BİLGİSAYAR & TEKNOLOJİ.::. > Web Master > asp.net

Yeni Konu aç  Cevapla
 
Seçenekler
Alt 29 March 2008, 12:57   Mesaj No:1

tamerr89

Papatyam Paylaşımcı Üyesi
Avatar Otomotik
Durumu:tamerr89 isimli Üye şimdilik offline konumundadır
Papatyam No : 1196
Üyelik T.: 09 December 2007
Arkadaşları:0
Cinsiyet:
Yaş:34
Mesaj: 212
Konular:
Beğenildi:
Beğendi:
Takdirleri:10
Takdir Et:
Konu Bu  Üyemize Aittir!
Standart Döküman yönetimi access database inde file upload and view as binary

Döküman yönetimi access database inde file upload and view as binary

Files.mdb diye bir access dosyasy olusturup yd-autonumberfilename-textfilesize-numbercontenttype-textfiledata-oleobject fieldlerini olusturun

<%@ Page Language="VB" debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<% ''////////////////////////////////////////////////////////////////
''File uploading by tamer [email protected]
''///////////////////////////////////////////////////////////////
Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim myReader As OleDbDataReader
Dim strSQLQuery As String
If Request.QueryString("mode&quot = "view" Then
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB .4.0; Data Source=" & Server.MapPath("Files.mdb&quot & ";&quot
strSQLQuery = "SELECT * FROM Files WHERE ID =" & Request.QueryString("file_id&quot & " "
objCommand = New OleDbCommand(strSQLQuery, objConnection)
objConnection.Open()
myReader = objCommand.ExecuteReader(System.Data.CommandBehavi or.CloseConnection)
If myReader.Read() Then
Dim fileData() As Byte = CType(myReader.Item("FileData&quot, Byte())
Response.Clear()
Response.AppendHeader("Content-Disposition", "attachment; filename=" + myReader.GetString(1))
Response.ContentType = myReader.GetString(3)
Response.OutputStream.Write(fileData, 0, fileData.Length)
Else
Response.Write("<p>No File to view.</p>&quot
End If
objConnection.Close()
Else
%><html>
<body>
<script language="VB" runat="server">
Sub btnUpload_OnClick(ByVal Src As Object, ByVal E As EventArgs)
If Fileupload1.HasFile Then
Dim files As HttpFileCollection = Request.Files
Dim i As Integer = 0
While i < Request.Files.Count
Dim file As HttpPostedFile = files(i)
If file.ContentLength > 0 Then
UploadFile(file)
End If
System.Math.Min(System.Threading.Interlocked.Incre ment(i), i - 1)
End While
files = Nothing
Else
Response.Write("<p>Chose a file.</p>&quot
End If
End Sub

Sub UploadFile(ByVal file As HttpPostedFile)
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB .4.0; Data Source=" & Server.MapPath("Files.mdb&quot & ";&quot
Dim CmdText As String = "INSERT INTO Files(FileName, FileSize, ContentType, FileData) VALUES (@FileName, @FileSize, @ContentType, @FileData)"
Dim fileName As String = Nothing
Dim contentType As String = file.ContentType
Dim fileLength As Integer = file.ContentLength
Dim fileData(fileLength) As Byte
Dim lastPos As Integer = file.FileName.LastIndexOf("\"c)
fileName = file.FileName.Substring(System.Threading.Interlock ed.Increment(lastPos))
file.InputStream.Read(fileData, 0, fileLength)
Try
Dim cmd As OleDbCommand = New OleDbCommand(CmdText, con)
Try
Dim pms As OleDbParameterCollection = cmd.Parameters
pms.Add("@FileName", OleDbType.VarChar, 50)
pms.Add("@FileSize", OleDbType.Integer)
pms.Add("@ContentType", OleDbType.VarChar, 50)
pms.Add("@FileData", OleDbType.VarBinary)
pms("@FileName&quot.Value = fileName
pms("@FileSize&quot.Value = fileLength
pms("@ContentType&quot.Value = contentType
pms("@FileData&quot.Value = fileData
pms = Nothing
con.Open()
cmd.ExecuteNonQuery()
Finally
CType(cmd, IDisposable).Dispose()
End Try
Finally
CType(con, IDisposable).Dispose()
End Try
End Sub
</script>
<%
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB .4.0; Data Source=" & Server.MapPath("Files.mdb&quot & ";&quot
If Request.QueryString("delete&quot <> "" Then
strSQLQuery = "Delete from Files where ID = " & Request.QueryString("delete&quot & " "
objCommand = New OleDbCommand(strSQLQuery, objConnection)
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
End If
strSQLQuery = "SELECT * FROM Files"
objCommand = New OleDbCommand(strSQLQuery, objConnection)
objConnection.Open()
myReader = objCommand.ExecuteReader(System.Data.CommandBehavi or.CloseConnection)

%>
<table bgcolor="gainsboro" border="1">
<form runat="server">
<tr bgcolor="navy">
<td colspan="4">
<asp:button id="btn_Upload" runat="server" text="Upload" tabindex="2" OnClick = "btnUpload_OnClick"></asp:button>
<asp:fileupload id="Fileupload1" runat="server" />
</td>
</tr>
</form>
<% If myReader.HasRows Then%>
<tr bgcolor="navy">
<td><font color=white face=tahoma size=2>FileName</font></td>
<td><font color=white face=tahoma size=2>FileSize</font></td>
<td><font color=white face=tahoma size=2>ContentType</font></td>
<td><font color=white face=tahoma size=2>Delete</font></td>
</tr>
<%While myReader.Read()%>
<tr>
<td><a href=main.aspx?file_id=<%=myReader.GetInt32(0)% >&mode=view><font face=tahoma size=2><%=myReader.GetString(1)%></font></a> </td>
<td><font face=tahoma size=2><%=formatnumber(myReader.GetInt32(2). ToString()/1000,2)%> Kb</font></td>
<td><font face=tahoma size=2><%=myReader.GetString(3)%></font></td>
<td><a href="main.aspx?delete=<%=myReader.GetInt3 2(0).ToString()%>"><font face=tahoma size=2 color=navy>Delete</font></a>
</tr>
<%End While
Else
Response.Write("<p>No records.</p>&quot
End If
myReader.Close()
objConnection.Close()
%>
</table>
</body>
</html>
<%End if%>



Alıntı ile Cevapla
Cevapla

Bookmarks

Konuyu Toplam 1 Üye okuyor. (0 Kayıtlı üye ve 1 Misafir)
 

Benzer Konular
Konu Başlıkları Konuyu Başlatan

Papatyam Forum Ana Kategori Başlıkları

Cevaplar Son Mesajlar
Ozon Tedavisi » 80\'inde bastonu attıran yöntem umut Tamamlayıcı Tıp 0 21 June 2011 14:18
Devler Lig'inde müthiş kapışma PESTEMAL Şampiyonlar Ligi & UEFA Kupası 0 16 September 2009 14:44
Binary - decimal ve decimal - binary çevirimi yapar tamerr89 C++ 0 29 March 2008 18:44
File upload islemi ve farkli kaydetme(güncellendi) tamerr89 asp.net 0 29 March 2008 13:08
Osmanli da devlet yönetimi PESTEMAL Osmanlı Tarihi 11 25 February 2008 11:39

Yeni Sayfa 1

www.papatyam.org Ana Sayfa

Tefekküre Davet Köşesi

Papatyam Sosyal Medya Guruplarımıza Katılın

                       Instagram         

Papatyam alemdarhost.com sunucularında barındırılmaktadır.