OpenFileDialog in cshtml

Can I find out how I can write something like this C # Opendialog in Razor? I am trying to make an openfiledialog that will prompt the user to upload a photo to the SqlServerCe database:

OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { string path = openFileDialog1.FileName; byte[] image = File.ReadAllBytes(path); string query = "UPDATE firma SET logo=@Image WHERE id = 1"; SqlCommand sqlCommand = new SqlCommand(query, conn); sqlCommand.Parameters.AddWithValue("@Image", image); conn.Open(); sqlCommand.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } 
+6
source share
1 answer

You cannot use a specific OpenFileDialog (a la C # / winforms / wpf) in a web application (without using Silverlight or another plugin).

All you can do is use the file input tag, which will force the browser to open the default browser dialog when the user clicks the browse button:

 <input type="file" name="elementName" /> 

When the form is submitted, this file will be included as part of the input stream.

For a complete specification of the <input> element, go here: http://www.w3schools.com/tags/tag_input.asp

+7
source

Source: https://habr.com/ru/post/957454/


All Articles