keyongtech


  keyongtech > dotnet.framework.aspnet.* > dotnet.framework.aspnet.main > 11/2006

 #1  
11-14-06, 10:11 PM
Keith Harris
Hi,

I would like to display a preview of a posted file.

To accomplish, this I am using storing the image bytes into cache and
setting the ImageUrl property of an image control to an aspx page named
ImagePreview.

The ImagePreview page should dynamically generates the appropriate response
but the image is not displaying properly.

I do not want to save the image on the web server.

Here is the code:

---------------------------------------------------------------------------------------------
(defalut.aspx)
---------------------------------------------------------------------------------------------
//in button_click event handler:
byte[] bytearray = null;
HttpPostedFile postedfile = FileUpload1.PostedFile;

//save the input stream as a byte array
using (System.IO.Stream stream = postedfile.InputStream)
{
int len = (int)postedfile.InputStream.Length;
bytearray = new byte[len];
stream.Read(bytearray, 0, len);
stream.Close();
}

//cache the byte array
string cachekey = Guid.NewGuid().ToString();
Cache.Add(cachekey, bytearray, null,
System.Web.Caching.Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20),
System.Web.Caching.CacheItemPriority.Default,
null);

string target = string.Format("ImagePreview.aspx?ct={0}&key={1}",

Server.UrlEncode(postedfile.ContentType),
cachekey);


imgUploadedFile.ImageUrl = target;

---------------------------------------------------------------------------------------------
(ImagePreview.aspx.cs)
---------------------------------------------------------------------------------------------
// in Page_Load event handler:
byte[] bytearray = (byte[])Cache[Request.Params["key"]];

Response.Expires = 0;
Response.Buffer = true;
Response.ClearContent();
Response.ContentType = Request.Params["ct"];

Response.BinaryWrite(bytearray);
Response.End();
=================================================

Does anyone know why the image is not displaying?

Thanks for any help,
-Keith
 #2  
11-15-06, 10:02 AM
Onwuka Emeka
Your code works fine. try to write the url of the image to the response
stream just to make sure the imageurl is being set properly. outside that
your code does work fine, it could be something as little as the button not
being attached to the eventhandler
"Keith Harris" <KeithHarris> wrote in message
news:3ba2
[..]
 #3  
11-15-06, 04:16 PM
Keith Harris
It doesn't work for me, I just get a broken image. The handlers are wired up
correctly, I stepped through the code to see that they bytes were being
returned.

"Onwuka Emeka" wrote:
[..]
Similar Threads
Help Correcting Sub-ledger Trx: Unposted, Posted TO GL, Posted ThruGL

Hello, I’m trying to understand the proper way to correct transactions from sub-ledgers depending on the status of the transaction. If you discover a sub-ledger unposted...

Table name for Posted invoices (sales) and posted receipts (purcha

Hello everyone, I have to create a select for selecting some information from those two tables, the problem is that I don't work with Navision and don't know anything about...

Posted File

Hi All, I am just wondering what options are available for checking the validity of a PostedFile uploaded using a standard fileupload control. I need to know how to check if...

Opening an OFT file posted on web site

Suddenly my OFT forms that are posted on a web site are not working. When anyone tries to open them, they get an error message saying the page is not available or that they...

Javascript works in Browser Preview but not when posted to the internet

I have a javascript page that I used sucessfully on the net three years ago. I am trying to use it again and although it works fine when I preview it in a browser, It won't...


All times are GMT. The time now is 03:34 AM. | Privacy Policy