Telerik RadUpload how to get bytes

Posted on: Tue Dec 01 13:33:44 -0800 2009. Updated on: Tue Dec 01 13:37:16 -0800 2009.
Category: DotNet

For use with the Telerik RadUpload COntrol. This shows how to quickly process an uploaded file in codebehind so you get it into a byte array ready to be put in the database.

protected void ButtonUpload_Click(object sender, EventArgs e)
{
    if (RadUpload1.UploadedFiles.Count > 0)
    {
        string filename = RadUpload1.UploadedFiles[0].FileName;
	int length = (int)RadUpload1.UploadedFiles[0].InputStream.Length;
	byte[] bytes = new byte[length];
	RadUpload1.UploadedFiles[0].InputStream.Read(bytes, 0, length);
        
        // Now simply call your Data Model function to create item, bytes contains data
        CreateFile(filename, bytes, RadUpload1.UploadedFiles[0].ContentType);
    }
}

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.