Last post Jan 06, 2014 05:08 PM by JT12
Jan 06, 2014 03:06 PM|JT12|LINK
In my web application I would like to add the ablilty to upload images & pdf files to the server, and store thier info (or the entire file) in the database with the id of the user that they belong to. Then the plan would be to allow the user to view all
of the files with that id.
I read this article and downloaded the example, but I receive an error when I run it.
Compiler Error Message: CS0117: 'WebMatrix.Data.Database' does not contain a definition for 'OpenFile'
Line 17: byte fileContent = new byte[fileLength];
Line 18: fileStream.Read(fileContent, 0, fileLength);
Line 19: var db = Database.OpenFile("FileUploading.sdf");
Line 20: var sql = "INSERT INTO Files (FileName, FileContent, MimeType) VALUES (@0,@1,@2)";
Line 21: db.Execute(sql, fileName, fileContent, fileMime);
I added Microsoft.Web.Helpers also and still receive the same error. (I read that the FileUpload helper is within Microsoft.Web.Helpers)
Jan 06, 2014 03:51 PM|Mikesdotnetting|LINK
That looks like an old v1.0 download of mine. I should update it. In the meantime, change line 19 to:
var db = Database.Open("FileUploading");
Jan 06, 2014 04:46 PM|JT12|LINK
Thanks. That fixed the issue.
Would it be possible to display PDFs in the browser or do they just need to be downloaded to view?
Jan 06, 2014 05:00 PM|Mikesdotnetting|LINK
Different browsers manage the display of PDFs in different ways. However, to take advantage of those that have an embedded PDF viewer, change the content-disposition from attachment to inline.
Jan 06, 2014 05:08 PM|JT12|LINK
That worked. Thanks!