我可以知道热吗?我可以在剃刀中写像这样的c#打开对话框吗?我正在尝试创建一个打开文件对话框,让用户可以将照片上传到SqlServerCe数据库中:
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);
}发布于 2013-11-06 05:47:56
你不能在web应用程序中使用特定的OpenFileDialog (比如c#/winforms/wpf) (不使用Silverlight或其他一些插件)。
你所能做的就是使用一个文件输入标签,当用户点击浏览按钮时,浏览器会打开默认的文件浏览器对话框:
<input type="file" name="elementName" />当表单发布时,该文件将作为输入流的一部分包括在内。
有关<input>元素的完整规范,请转到此处:http://www.w3schools.com/tags/tag_input.asp
https://stackoverflow.com/questions/19799319
复制相似问题