File Information

Dec 27, 2008 at 7:10 AM
Edited Dec 28, 2008 at 2:46 AM
How do we get the basic file information such as:

- original filename
- file size
- file type

I've tried to get this from HttpPostedFile(context.Request.Files) but it contains no items.
Basically, I'm trying to save the file information to database for each uploaded files.

Dec 29, 2008 at 5:13 AM
You will need to be a little more specific. Where do you want this information? In silverlight, the aspx page, or the http handler where it is being uploaded?

From: [email removed]
To: [email removed]
Date: Fri, 26 Dec 2008 23:10:39 -0800
Subject: File Information [SilverlightFileUpld:43050]

From: tonyctlu
How do I find out the basic file information such as:

- original filename
- file size
- file type

Also, is there a way to find out the total number of files has uploaded?

Read the full discussion online.
To add a post to this discussion, reply to this email (
To start a new discussion for this project, email
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at

It’s the same Hotmail®. If by “same” you mean up to 70% faster. Get your account now.
Dec 29, 2008 at 7:22 AM
Hi Darick,
Yes, in HTTP handler. I saw you mentioned in the other discussion, we will get it from the QueryString, so we need to append those info to the QueryString from the source code. Do I modify the FileUpload.cs and rebuild the .dll? How many files I need to replace in the web project?
Aug 7, 2009 at 6:54 AM

I'm still kinda waiting for this thread to continue :)

If I can get the filename & path  in HTTP Handler, then how do i insert it into database so that my silverlight page will recognized it? I'm having problem with saving the file information to the database..


Please help,


Aug 7, 2009 at 7:30 AM
You may use my code for reference:
In FileUpload.ashx:
namespace SilverlightFileUploadWeb
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    //[WebService(Namespace = "")]
    //[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class FileUpload : IHttpHandler, IRequiresSessionState
        private HttpContext ctx;

        public void ProcessRequest(HttpContext context)
            ctx = context;
            string uploadPath = context.Server.MapPath("");
                FileUploadProcess fileUpload = new FileUploadProcess();
                fileUpload.FileUploadCompleted += new FileUploadCompletedEvent(fileUpload_FileUploadCompleted);
                fileUpload.ProcessRequest(context, uploadPath);

        void fileUpload_FileUploadCompleted(object sender, FileUploadCompletedEventArgs args)
            string id = ctx.Request.QueryString["id"];

            string sourceFullName = args.FilePath;
            string destFolderPath = (string)ctx.Session["UploadPath"];
            InsertFile(sourceFullName, destFolderPath, ctx);


        public bool InsertFile(string sourceFullName, string destFolderPath, HttpContext context)

            FileInfo fi = new FileInfo(sourceFullName);
            string strOriginalFileName = System.IO.Path.GetFileName(fi.Name);

            SqlConnection PrizmDAM = new SqlConnection(YourDBConnectionString);
            SqlCommand cmdInsert = new SqlCommand();
            cmdInsert.CommandType = CommandType.Text;
            cmdInsert.CommandText = "INSERT INTO tblFiles (strOriginalFileName, strType, intSize) VALUES (@strOriginalFileName, @strType, @intSize)";
            cmdInsert.Connection = PrizmDAM;
            cmdInsert.Parameters.AddWithValue("@strOriginalFileName", strOriginalFileName);
            cmdInsert.Parameters.AddWithValue("@strType", System.IO.Path.GetExtension(fi.Extension));
            cmdInsert.Parameters.AddWithValue("@intSize", (long)fi.Length);


            return true;

        public bool IsReusable
                return false;

Hope this helps.
Aug 7, 2009 at 1:08 PM

Wow thanks for sharing! :)

Sep 4, 2009 at 4:07 AM

what if i want just the filename uploaded and display the filename on the aspx page?