Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 158155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:37:53+00:00 2026-05-11T10:37:53+00:00

My WPF application gets a file from the user with Microsoft.Win32.OpenFileDialog()… Private Sub ButtonUpload_Click(…)

  • 0

My WPF application gets a file from the user with Microsoft.Win32.OpenFileDialog()…

Private Sub ButtonUpload_Click(...)     Dim FileOpenStream As Stream = Nothing     Dim FileBox As New Microsoft.Win32.OpenFileDialog()     FileBox.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)     FileBox.Filter = 'Pictures (*.jpg;*.jpeg;*.gif;*.png)|*.jpg;*.jpeg;*.gif;*.png|' & _                      'Documents (*.pdf;*.doc;*.docx;)|*.pdf;*.doc;*.docx;|' & _                      'All Files (*.*)|*.*'     FileBox.FilterIndex = 1     FileBox.Multiselect = False     Dim FileSelected As Nullable(Of Boolean) = FileBox.ShowDialog(Me)     If FileSelected IsNot Nothing AndAlso FileSelected.Value = True Then         Try             FileOpenStream = FileBox.OpenFile()             If (FileOpenStream IsNot Nothing) Then                 Dim ByteArray As Byte()                 Using br As New BinaryReader(FileOpenStream)                     ByteArray = br.ReadBytes(FileOpenStream.Length)                 End Using                 Dim z As New ZackFile                 z.Id = Guid.NewGuid                 z.FileData = ByteArray                 z.FileSize = CInt(ByteArray.Length)                 z.FileName = FileBox.FileName.Split('\').Last                 z.DateAdded = Now                 db.AddToZackFile(z)                 db.SaveChanges()             End If         Catch Ex As Exception             MessageBox.Show('Cannot read file from disk. ' & Ex.Message, 'Fail', MessageBoxButton.OK, MessageBoxImage.Error)         Finally             If (FileOpenStream IsNot Nothing) Then                 FileOpenStream.Close()             End If         End Try     End If End Sub 

And my ASP.NET MVC application serves it up for download at a web site with FileStreamResult()…

Public Class ZackFileController     Inherits System.Web.Mvc.Controller      Function Display(ByVal id As Guid) As FileStreamResult         Dim db As New EfrDotOrgEntities         Dim Model As ZackFile = (From z As ZackFile In db.ZackFile _                                 Where z.Id = id _                                 Select z).First         Dim ByteArray As Byte() = Model.ImageData         Dim FileStream As System.IO.MemoryStream = New System.IO.MemoryStream(ByteArray)         Dim ContentType As String = ?????         Dim f As New FileStreamResult(FileStream, ContentType)         f.FileDownloadName = Model.FileName         Return f     End Function  End Class 

But FileStreamResult() needs a content type string. How do I know the correct content type of my file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:37:54+00:00Added an answer on May 11, 2026 at 10:37 am

    I’ve replaced the FileExtension column in my database table with a ContentType column.

    I populate it when I upload a file.

    Private Sub ButtonUpload_Click(...)     ...     Dim FileExtension As String = '.' + FileBox.FileName.Split('.').Last.ToLower     z.ContentType = ContentType(FileExtension)     ... End Sub 

    I determine the content type with this function:

    Function ContentType(ByVal FileExtension As String) As String     Dim d As New Dictionary(Of String, String)     'Images'     d.Add('.bmp', 'image/bmp')     d.Add('.gif', 'image/gif')     d.Add('.jpeg', 'image/jpeg')     d.Add('.jpg', 'image/jpeg')     d.Add('.png', 'image/png')     d.Add('.tif', 'image/tiff')     d.Add('.tiff', 'image/tiff')     'Documents'     d.Add('.doc', 'application/msword')     d.Add('.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')     d.Add('.pdf', 'application/pdf')     'Slideshows'     d.Add('.ppt', 'application/vnd.ms-powerpoint')     d.Add('.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation')     'Data'     d.Add('.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')     d.Add('.xls', 'application/vnd.ms-excel')     d.Add('.csv', 'text/csv')     d.Add('.xml', 'text/xml')     d.Add('.txt', 'text/plain')     'Compressed Folders'     d.Add('.zip', 'application/zip')     'Audio'     d.Add('.ogg', 'application/ogg')     d.Add('.mp3', 'audio/mpeg')     d.Add('.wma', 'audio/x-ms-wma')     d.Add('.wav', 'audio/x-wav')     'Video'     d.Add('.wmv', 'audio/x-ms-wmv')     d.Add('.swf', 'application/x-shockwave-flash')     d.Add('.avi', 'video/avi')     d.Add('.mp4', 'video/mp4')     d.Add('.mpeg', 'video/mpeg')     d.Add('.mpg', 'video/mpeg')     d.Add('.qt', 'video/quicktime')     Return d(FileExtension) End Function 

    This works, but it seems inelegant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer What you see on the screen of your iPhone is… May 11, 2026 at 11:49 am
  • added an answer As several others have pointed out in general this is… May 11, 2026 at 11:49 am
  • added an answer I have been told that a good toolkit for doing… May 11, 2026 at 11:49 am

Related Questions

I want my WPF application to be skinnable, by applying a certain XAML template,
I've created an attached behaviour in my WPF application which lets me handle the
Can I host an XBAP in my WPF application dynamically? Can I download an
I'm trying to use the FolderBrowserDialog from my WPF application - nothing fancy. I
Is there a way for me to have the Window of my WPF application
Im trying to define a dataTemplate for a business object in my wpf application
Can I stream a live video in WPF application from my web cam? If
I am attempting to rewrite my ForestPad application utilizing WPF for the presentation layer.
I'm working on a simple application to start learning my way around WPF. I
My application (written in WPF/C#) will monitor a live video source and will need

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.