- sziku69: Szólánc.
- sziku69: Fűzzük össze a szavakat :)
- Luck Dragon: Asszociációs játék. :)
- gban: Ingyen kellene, de tegnapra
- D1Rect: Nagy "hülyétkapokazapróktól" topik
- N€T0X|N: Stellar Blade után
- pr1mzejEE: Viszlát CoD2, CoD4, CS:GO!
- ubyegon2: Airfryer XL XXL forrólevegős sütő gyakorlati tanácsok, ötletek, receptek
- weiss: Pant* rant
- Bezzeg annak idején...
Ú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!
- Új Honor 400 pro + 66 wattos töltőfej
- ASUS TUF Gaming A620M-Plus + AMD Ryzen 5 8400F + 16GB 5600MHz Kingston Fury Beast + hűtő
- Eladó Erős Gamer PC - Akár Cyberpunk 2077-re Is Készen! (Ryzen 3 2200G RX 570 8GB 32GB RAM AIO
- MacBook Pro 2019 '16 2,6 Ghz 6mag Intel Core i7 16/512gb - Space Gray Touch Bar
- Xiaomi 13T 256GB, Kártyafüggetlen, 1 Év Garanciával
- 119 - Lenovo Legion Pro 5 (16ARX8) - AMD Ryzen 7 7745HX, RTX 4070 (48 hónap garancia!) (ELKELT)
- Macbook White 13" unibody
- NEC MultiSync V421 monitor (42") 1920 x1080px
- Steam, EA, Ubisoft és GoG játékkulcsok, illetve Game Pass kedvező áron, egyenesen a kiadóktól!
- 123 - Lenovo Legion Pro 5 (16ARX8) - AMD Ryzen 7 7745HX, RTX 4070 (48 hónap garancia!)
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest