0

I have an application that allows a user to upload a certificate and attach it to a person within the system. Currently it is written to only accept .PDF files, but now the client wants the flexibility to upload any type of document into the system. I have set up the database to hold the byte[] file and the file extension, but I don't know how to make the system smart enough to be this flexible and open any file type I throw at it without hard coding all of the instances. Any ideas?

EDIT: Currently I am doing the following.

private void createPDF(byte[] file, string Name)
{
    int fileSize = file.Length;

    Response.AppendHeader("content-length", fileSize.ToString());
    Response.ContentType = "application/pdf";
    if (!Name.Contains("."))
        Name = Name + ".pdf";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + Name);
    Response.BinaryWrite(file);
    //Response.Clear();
    Response.Flush();
    Response.End();
}

However, I need to now be able to send in the extension and have it open. The document needs to be able to be downloaded by the end user. I will limit the uploading to not allow any malicious file extensions, figured that was a given. Thanks guys, this flu bug is kicking my butt and I can't think straight...

4

1 回答 1

2

The octet-stream mime-type should work.

private void createFILE(byte[] file, string Name)
{
    int fileSize = file.Length;

    Response.AppendHeader("content-length", fileSize.ToString());
    Response.ContentType = "octet-stream";
    if (!Name.Contains("."))
        Name = Name + ".(your_extension)";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + Name);
    Response.BinaryWrite(file);
    Response.Flush();
    Response.End();
}
于 2013-01-10T21:00:25.513 回答