【发布时间】:2014-07-23 09:29:13
【问题描述】:
我有一个带有浏览按钮的表单,当我点击它时,对话框打开并且我选择了一个文件,现在该文件的路径或文件名将显示在文本框中我已经编写了代码但文件路径不是显示在文本框中,我尝试解决但失败了,请让我摆脱这个,还有一件事,我想把它上传到特定文件夹然后下载到我的系统上,请告诉我这个也
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.IO;
//using System.Drawing;
using System.ComponentModel;
namespace RIS_2
{
/// <summary>
/// Interaction logic for crud.xaml
/// </summary>
public partial class crud : Window
{
public crud()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
}
private void browse_btn_Click(object sender, RoutedEventArgs e)
{
Stream checkStream = null;
// OpenFileDialog op1 = new OpenFileDialog();
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Multiselect = false;
dlg.Filter = "All Image Files | *.*";
//dlg.Filter = "(*.pfw)|*.pfw|All files (*.*)|*.*";
Nullable<bool> result = dlg.ShowDialog();
// if ((bool)dlg.ShowDialog())
if(result==true)
{
try
{
if ((checkStream = dlg.OpenFile()) != null)
{
// MyImage.Source = new BitmapImage(new Uri(dlg.FileName, UriKind.Absolute));
//listBox1.Items.Add(openFileDialog.FileName);
string filename = dlg.FileName;
tb_file.Text = filename;
// tb_file.AppendText(dlg.FileName.ToString());
MessageBox.Show("Successfully done", filename);
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
else
{
MessageBox.Show("Problem occured, try again later");
}
}
}
}
【问题讨论】:
-
我想将它上传到特定文件夹,然后下载到我的系统上...这是对您要求的糟糕描述。显示选中的文件路径后,你到底要做什么?
-
首先我要上传它,上传成功后,另一个用户可以下载它或通过引用该文件的另一个表单查看它
-
但是上传到哪里下载???月亮?我们不知道...如果您真的确实需要帮助,请与我们分享您的要求。
-
实际上我想将文件存储在数据库中(pdf,图像,doc等),然后其他用户可以从数据库中下载它