Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
File upload
mercoledì 17 dicembre 2014 - 19.02
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
adachigahara
Profilo
| Newbie
15
messaggi | Data Invio:
mer 17 dic 2014 - 19:02
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace Logistica.FOGLIOMATRICOLA
{
/// <summary>
/// Descrizione di riepilogo per foto
/// </summary>
public class foto : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
FileStream fs = null;
MemoryStream streamReader = null;
MemoryStream streamWriter = null;
byte[] immagine = null;
Bitmap bmpOut = null;
Bitmap loBMP = null;
Graphics g = null;
DataTable dt = ManagerUser.GetAllUser(Convert.ToInt32(context.Request.QueryString["id_utente"]), "", "", "", "", "", "", "", "", "", "", "","","", "","","","","","","","","");
streamReader = new MemoryStream((byte[])dt.Rows[0]["foto"]);
if (context.Request.UrlReferrer.Segments[context.Request.UrlReferrer.Segments.Length - 1].Equals("RicercaFoglio.aspx"))
{
loBMP = new Bitmap(streamReader);
bmpOut = new Bitmap(30, 40);
g = Graphics.FromImage(bmpOut);
g.FillRectangle(Brushes.White, 0, 0, 30, 40);
g.DrawImage(loBMP, 0, 0, 30, 40);
}
else
{
bmpOut = new Bitmap(streamReader);
g = Graphics.FromImage(bmpOut);
g.DrawImage(bmpOut, new Point(0, 0));
}
streamWriter = new MemoryStream();
bmpOut.Save(streamWriter, ImageFormat.Jpeg);
//bmpOut.Save(context.Server.MapPath(".")+"\\foto\\foto"+context.Request.QueryString["id_utente"]+".jpg");
immagine = streamWriter.GetBuffer();
context.Response.BinaryWrite(immagine);
immagine = null;
context.Response.Flush();
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
Salve.. tramite questa classe riesco a caricare file riguardanti foto.. volevo sapere se mi potete dare una mano per far si che carica anche file di altre estensioni.. vi ringrazio anticipatamente per l'aiuto
0v3rCl0ck
Profilo
| Guru
1.120
messaggi | Data Invio:
ven 19 dic 2014 - 13:22
Ciao Giuseppe, per favore formatta il codice, altrimenti di solito difficilmente qualcuno prenderà in carico il thread, di fatto chiudendolo ancora prima di mettercisi a leggerlo, perchè troppo incasinato, non indentato ecc... in altre parole, aiutaci che noi ti aiutiamo
per formattare il codice mantenendo l'indentazione non devi fare altro che racchiudere il codice tra [code ] [/code ] senza spazio prima della parentesi ]
grazie,
Michael Denny | Microsoft Visual C# MVP
http://blogs.dotnethell.it/Regulator/
http://dennymichael.net
http://mvp.microsoft.com/mvp/Michael%20Denny-5000735
Twitter: @dennymic
adachigahara
Profilo
| Newbie
15
messaggi | Data Invio:
ven 19 dic 2014 - 16:29
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace Logistica.FOGLIOMATRICOLA
{
/// <summary>
/// Descrizione di riepilogo per foto
/// </summary>
public class foto : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
FileStream fs = null;
MemoryStream streamReader = null;
MemoryStream streamWriter = null;
byte[] immagine = null;
Bitmap bmpOut = null;
Bitmap loBMP = null;
Graphics g = null;
DataTable dt = ManagerUser.GetAllUser(Convert.ToInt32(context.Request.QueryString["id_utente"]), "", "", "", "", "", "", "", "", "", "", "","","", "","","","","","","","","");
streamReader = new MemoryStream((byte[])dt.Rows[0]["foto"]);
if (context.Request.UrlReferrer.Segments[context.Request.UrlReferrer.Segments.Length - 1].Equals("RicercaFoglio.aspx"))
{
loBMP = new Bitmap(streamReader);
bmpOut = new Bitmap(30, 40);
g = Graphics.FromImage(bmpOut);
g.FillRectangle(Brushes.White, 0, 0, 30, 40);
g.DrawImage(loBMP, 0, 0, 30, 40);
}
else
{
bmpOut = new Bitmap(streamReader);
g = Graphics.FromImage(bmpOut);
g.DrawImage(bmpOut, new Point(0, 0));
}
streamWriter = new MemoryStream();
bmpOut.Save(streamWriter, ImageFormat.Jpeg);
//bmpOut.Save(context.Server.MapPath(".")+"\\foto\\foto"+context.Request.QueryString["id_utente"]+".jpg");
immagine = streamWriter.GetBuffer();
context.Response.BinaryWrite(immagine);
immagine = null;
context.Response.Flush();
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
} [/code ]
sperodi averlo fatto bene... cmq volevo sapere se mi potete dare una mano, in quanto vorrei che oltre a file di tipo immagine posso caricare file anche con altre estensioni, e inoltre come posso fare una volta caricato il file farlo vedere in modo che chi vuole cliccarci sopra si apre ? spero di essermi spiegato , forse utilizzando un datagridview?
0v3rCl0ck
Profilo
| Guru
1.120
messaggi | Data Invio:
ven 19 dic 2014 - 19:53
togli lo spazio (che io ti ho messo per non farlo prendere dal sistema)
[/code ]
deve diventare
[/code]
Michael Denny | Microsoft Visual C# MVP
http://blogs.dotnethell.it/Regulator/
http://dennymichael.net
http://mvp.microsoft.com/mvp/Michael%20Denny-5000735
Twitter: @dennymic
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !