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!
- Eladó LG OLED42C31LA 120Hz (garanciális, hibátlan állapotban)
- Katonai Rugged laptopok Panasonic Toughbook és Getac S410 6-11.gen gar.
- Lenovo ThinkPad P1 G2 Tervező Vágó Laptop -70% 15,6" Xeon E-2276M 32/1TB QUADRO T2000 4GB FHD
- Dell OptiPlex 3050 számítógép (I3/8gb/240SSD)
- Lenovo Thinkpad T495s Ryzen 5 PRO 3500U/16GB RAM/256 SSD/14" FHD touch Magyar bill. laptop eladó
- Samsung Galaxy S23+ 256GB, Kártyafüggetlen, 1 Év Garanciával
- LG 65" C1 OLED - 4K 120Hz 1ms - NVIDIA G-Sync - FreeSync Premium - HDMI 2.1 - PS5 és Xbox Ready!
- GYÖNYÖRŰ iPhone 11 128GB Black -1 ÉV GARANCIA - Kártyafüggetlen, MS3263, 100% Akkumulátor
- GYÖNYÖRŰ iPhone 12 mini 128GB Purple -1 ÉV GARANCIA - Kártyafüggetlen, MS3327, 94% Akkumulátor
- Tablet felvásárlás!! Apple iPad, iPad Mini, iPad Air, iPad Pro
Állásajánlatok
Cég: CAMERA-PRO Hungary Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest