日期:2014-05-17  浏览次数:20367 次

asp.net 选择文件保存路径该怎么实现??????

  我下面的备份代码该怎么改进才能实现保存路径的选择呢???


C# code
 protected void btnBackUp_Click(object sender, EventArgs e)  
    {
        string ConnctionString = "Data Source=.;User ID=sa;Password=123;Database='" + this.dbName.SelectedValue + "'";
        string dbbackupfilepath = Server.MapPath("~/DBBackUpFile/DataBase");
        string strSQL = "backup database " + this.dbName.SelectedValue + " to disk='" + dbbackupfilepath + "\\" + this.tbPosition.Text.Trim() + ".bak'";
            

            try
        {
            //判断该路径下是否已经有该文件了
            if (File.Exists(dbbackupfilepath + "\\" + this.tbPosition.Text.Trim() + ".bak"))
            {
                //存在此文件,提示错误
                   ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('文件名已存在,请重新命名!');</script>");
                      return;
            }
            else
            {
                using (SqlConnection con = new SqlConnection(ConnctionString))
                {
                    con.Open();                  
                   
                    using (SqlCommand cmd = new SqlCommand(strSQL, con))
                        {
                            cmd.ExecuteNonQuery();
                            ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('数据库备份成功!');</script>");
                            
                        }
                 }
                  
                
            }
        }
        catch (Exception ex)
        {
            ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('备份数据库失败!原因是:" + ex.Message + "');</script>");
        }
    }


------解决方案--------------------
手动选择保存路径好像要自己绘制选择对话框,b/s中很少见到这种做法,一般采用将存储路径放在配置文件中,达到不需要修改程序,修改存储路径的效果。
------解决方案--------------------
添加个下拉列表框,选择路劲。把路劲传到后台代码。
------解决方案--------------------
探讨

添加个下拉列表框,选择路劲。把路劲传到后台代码。

------解决方案--------------------
 

有个控件FILEUPLOAD也许对你有帮助,代码你再优化吧。。。
------解决方案--------------------
可能你要关监狱了 呵呵
------解决方案--------------------
看了这段代码你就知道了
protected override void dataProduct_MouseDoubleClick(object sender, MouseEventArgs e)
{
base.dataProduct_MouseDoubleClick(sender, e);
if (dataProduct.CurrentCell.ColumnIndex != -1)
{
int indexNum = dataProduct.CurrentCell.ColumnIndex;
string ColumnText = dataProduct.Columns[indexNum].HeaderText.ToString();
string strsNO = dataProduct.Rows[dataProduct.CurrentRow.Index].Cells["序号"].EditedFormattedValue.ToString().Trim();
string strhtNO = dataProduct.Rows[dataProduct.CurrentRow.Index].Cells["h_code"].EditedFormattedValue.ToString().Trim();
if (ColumnText == "附件")
{
OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
OpenFileDialog1.Filter = "All files (*.*)|*.*|(*.pdf)|*.pdf|(*.xls)|*.xls|(*.doc)|*.doc|(*.jpg)|*.jpg";
OpenFileDialog1.FilterIndex = 0;
OpenFileDialog1.Title = "";
OpenFileDialog1.Multiselect = false;
if (OpenFileDialog1.ShowDialog() == DialogResult.OK)