29 March 2008, 12:57 | Mesaj No:1 |
Durumu:
Papatyam No :
1196
Üyelik T.:
09 December 2007
Arkadaşları:0
Cinsiyet:
Yaş:34
|
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" = "view" Then objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB .4.0; Data Source=" & Server.MapPath("Files.mdb" & ";" strSQLQuery = "SELECT * FROM Files WHERE ID =" & Request.QueryString("file_id" & " " 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", 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>" 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>" 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" & ";" 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".Value = fileName pms("@FileSize".Value = fileLength pms("@ContentType".Value = contentType pms("@FileData".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" & ";" If Request.QueryString("delete" <> "" Then strSQLQuery = "Delete from Files where ID = " & Request.QueryString("delete" & " " 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>" End If myReader.Close() objConnection.Close() %> </table> </body> </html> <%End if%> |
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 |
Tefekküre Davet Köşesi |
|
Papatyam Sosyal Medya Guruplarımıza Katılın |