ContentType of uploaded/downloaded file?

Last post 01-18-2007, 11:10 AM by Adam. 4 replies.
Sort Posts: Previous Next
  •  01-11-2007, 8:39 AM 25709

    ContentType of uploaded/downloaded file?

     
    How can I get the ContentType of the file on upload so that on download I can properly set the ContentType. I notice in your CustomFileProvider on the download page, that the line setting the content type on the Response object is commented. When downloading "uploadable documents", this causes the data to be displayed on the page and rather than IE treating it as a particular file type (.doc, .xls, etc).
     
    Any thoughts?
  •  01-17-2007, 8:30 AM 25849 in reply to 25709

    Re: ContentType of uploaded/downloaded file?

    Crickets? Where is the support?
  •  01-17-2007, 2:05 PM 25870 in reply to 25709

    Re: ContentType of uploaded/downloaded file?

    >>How can I get the ContentType of the file on upload so that on download I can properly set the ContentType.
     
    Where do you want to get this? Are you storing the files into DB?
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  01-18-2007, 8:45 AM 25909 in reply to 25870

    Re: ContentType of uploaded/downloaded file?

    "Where do yout want to get this". That is essentially my question rather, where is it available to me? Yes I am storing files in the database. I need the ContentType at download time so I can properly send the correct ContentType to the browser.
     
    There are two solutions I am familiar with:
     
    1) Get and store the ContentType sent by the browser for the file on upload. Since upload is encapsulated in the CuteEditor control, the control would need to make the ContentType available at upload time.
     
    2) Keep a "static" list of allowable content types and their extensions and use the appropriate ContentType at download time.
     
    The ideal solution is 1, but I am having a hard time finding a place where the CuteEditor makes the ContentType available. 2 is doable but not ideal from a maintenance perspective.
     
     
     
     
  •  01-18-2007, 11:10 AM 25913 in reply to 25909

    Re: ContentType of uploaded/downloaded file?

    1.
     
    I need to check the code and get back to you as soon as possible.
     
    2.
     
    private string getContentTypefromFileName(string Filename)
     {
      if (Filename.IndexOf(".") == -1)
      {
       return "text/plain";
      }
      else
      {
       string extension = Filename.Substring(Filename.IndexOf("."));
       if (extension == ".exe")
        return "application/octet-stream";
       else if (extension == ".txt")
        return "text/plain";
       else if (extension == ".jpg")
        return "image/jpeg";
       else if (extension == ".gif")
        return "image/gif";
       else
        throw new NotSupportedException("Unknown extension");
      }
     }

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View as RSS news feed in XML