Hirdetés
Új hozzászólás Aktív témák
-
QuippeR
tag
válasz
Inv1sus
#1071
üzenetére
Ha esetleg még nem ugrott az ötösöd, akkor segítek:
<%@ WebHandler Language="C#" Class="FileStream" %>
using System;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Reponsible for flushing out the file from the database to the user.
/// </summary>
public class FileStream : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
// get the file id
string fileId = context.Request.QueryString["file"];
using (SqlCommand command = new SqlCommand())
{
// get the file from database
command.Connection = new SqlConnection("connectionstring");
command.CommandText = "SELECT * FROM files where file_id = @FileId";
command.Parameters.AddWithValue("@FileId", fileId);
command.Connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
// flush out the binary data to the user
context.Response.Clear();
context.Response.ContentType = (string) reader["file_type"];
context.Response.AddHeader("Content-Disposition", String.Format("inline;filename={0};", reader["file_name"].ToString()));
context.Response.AddHeader("Content-Length", reader["file_size"].ToString());
context.Response.BinaryWrite((byte[]) reader["file_content"]);
context.Response.End();
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}Ezt mentsd le egy FileStream.ashx nevű fájlba. A lényege, hogy az url-ben megadod a fájlt id-jét például így: http://localhost/FileStream.ashx?file=4. Az adatbázisban persze a megfelelő adatoknak (file_name, file_size, file_type, file_content) benne kell lennie ehhez.
A feltöltésnél így tudod kiszedni ezeket az értékeket egy fuNewUpload nevű FileUpload controlból:
string filename = fuNewUpload.PostedFile.FileName.Substring(fuNewUpload.PostedFile.FileName.LastIndexOf('\\') + 1);
string filetype = fuNewUpload.PostedFile.ContentType;
int filesize = fuNewUpload.PostedFile.ContentLength;
byte[] filecontent = new byte[fuNewUpload.PostedFile.ContentLength];
fuNewUpload.PostedFile.InputStream.Read(filecontent, 0, fuNewUpload.PostedFile.ContentLength);
Új hozzászólás Aktív témák
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- One mobilszolgáltatások
- Kuponkunyeráló
- LED világítás a lakásban
- OFF TOPIC 44 - Te mondd, hogy offtopic, a te hangod mélyebb!
- VHS digitalizálás
- NVIDIA GeForce RTX 5080 / 5090 (GB203 / 202)
- Path of Exile (ARPG)
- Luck Dragon: Asszociációs játék. :)
- Azonnali alaplapos kérdések órája
- Milyen routert?
- További aktív témák...
- Apple iPhone 11 64GB, Kártyafüggetlen, 1 Év Garanciával
- Apple iPhone 11 64GB, Kártyafüggetlen, 1 Év Garanciával
- Apple iPhone 11 64GB, Kártyafüggetlen, 1 Év Garanciával
- Apple iPad 9th Gen 256GB, Wi-Fi+Cellular, Kártyafüggetlen, 1 Év Garanciával
- Samsung Galaxy A53 5G 128GB, Kártyafüggetlen, 1 Év Garanciával
- MSI Katana GF76 - 17.3"FHD 144Hz - i5-11400H - 8GB - 512GB - Win11 - RTX 3050 Ti - MAGYAR
- BESZÁMÍTÁS! MSI X99A i7 5820K 16GB DDR4 240GB SSD 1TB HDD GTX 1050Ti 4GB Deepcool Ducase V2 600W
- BESZÁMÍTÁS! Xiaomi 15 Ultra 5G 16GB / 512GB okostelefon garanciával hibátlan működéssel
- GYÖNYÖRŰ iPhone 13 128GB Midnight -1 ÉV GARANCIA - Kártyafüggetlen, MS3580, 100% Akkumulátor
- HIBÁTLAN iPhone 13 Pro 128GB Graphite -1 ÉV GARANCIA - Kártyafüggetlen, MS3747, 100% Akkumulátor
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopműhely Bt.
Város: Budapest


