This is a migrated thread and some comments may be shown as answers.

What control doI use to view uploaded files?

5 Answers 192 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Garth
Top achievements
Rank 1
Garth asked on 24 Sep 2010, 10:11 PM
What control doI use to view uploaded files after they are uploaded?

For example:  I'll upload Word, Excel, PDF, PNG, TIFF, etc. files that will be stored into a varbinary(MAX) column.

What control do I use in an SL app to view the stored files?

5 Answers, 1 is accepted

Sort by
0
Fletcher Aluminium
Top achievements
Rank 1
answered on 26 Sep 2010, 10:11 PM
Hi Garth,

I do not believe there a control which will allow you to view the files in the actual SL application.  However, how I am currently handling my file upload and then view, is to store the files in the database, and then display them in a generic List Box control (you can customize the template to include things like deletion and anything else you want).  Then I am handling the click event of the List Box control, and then invoke a Javascript function on the ASPX container web page which accepts a FileID which is the unique identifier of your file you uploaded, and then it redirects you to a new Web Page (which I have called DocumentViewer.aspx) which then handles the file and displays it.  And example of this is here.

protected void Page_Load(object sender, EventArgs e)
{
    string ID= Request["id"];
 
    Entities qie = new Entities();
     
    FileStore file = qie.FileStores.Where(a => a.FileID == id).SingleOrDefault();
 
    this.Title = file.Name;
 
    Response.Clear();
    Response.BufferOutput = true;
    Response.ContentType = file.MIMEType;
    if (!file.MIMEType.ToLower().Contains("image"))
    {
        Response.AddHeader("Content-Disposition", "attachment; filename=" +
        file.Name + file.Extension);
    }
    Response.BinaryWrite(file.FileData.ToArray());
    Response.End();
}

So this pretty much says, that any image MIMEType will show in the new browser window that opens up, or else it will prompt the user to either Open or Save the file which they clicked on.  This way, you can put any type of file in there, be it PDF, Image files, Word Docs, or even saved Email Messages.  However, if you want to, you could make your Silverlight app an out of browser application, and then using the WebBrowser control, display the images or files directly into the Silverlight App.

Hope this has helped at all,


Shaun
0
Garth
Top achievements
Rank 1
answered on 28 Sep 2010, 03:15 AM
Thanks, Shaun.  Great answer!
0
Fletcher Aluminium
Top achievements
Rank 1
answered on 28 Sep 2010, 03:23 AM
Hey Garth,

No problem.  I hope it helped point you in the right direction, let me know if you had any great epiphanies as to how to make it that much better.

Cheers,


Shaun
0
Swapnadip
Top achievements
Rank 1
answered on 23 Apr 2012, 04:08 PM
Thanks shaun its a great answer.. But is it possible to do this in MVC3 RAZOR...and i want to download the attachments also.. how can i do it. i'm trying this since 2 days but unable to do that
0
Fletcher Aluminium
Top achievements
Rank 1
answered on 23 Apr 2012, 10:59 PM
Hey Swapnadip,

I haven't really touched much on MVC3 yet.  I have only just started doing some work with it just recently. However, it also depends on the type of attachments/files that you are wanting to display on your MVC3 Website.  For example, for a PDF you should be able to use something like PDF in Partial View.  And then on that page, or below it or something have a download button which will allow the user to download it.  A quick good search of downloading files off a MVC3 Website should give you some good results. For example:
public ActionResult Download()
{
    var document = ...
    var cd = new System.Net.Mime.ContentDisposition
    {
        // for example foo.bak
        FileName = document.FileName,
 
        // always prompt the user for downloading, set to true if you want
        // the browser to try to show the file inline
        Inline = false,
    };
    Response.AppendHeader("Content-Disposition", cd.ToString());
    return File(document.Data, document.ContentType);
}
Then just store the file path of the document they are viewing and create a document object where it says var document = ... and you should be able to do what you want.

However, in ASP.Net i know putting:
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name + file.Extension);

Before you display the page, will cause it to pop-up with a Save, Run, Cancel dialog box.

Hope this helps.
Tags
Upload
Asked by
Garth
Top achievements
Rank 1
Answers by
Fletcher Aluminium
Top achievements
Rank 1
Garth
Top achievements
Rank 1
Swapnadip
Top achievements
Rank 1
Share this question
or