我用FolderBrowserDialog.SelectedPath 获取文件夹的路径为file="C:\abc1\abc2",假设文件名filename="filename".那我把这2个组合起来就是一个路径,方法是:string filePath=file+"\\"+filename.
但是我用这个路径的调试时候发现系统给filePath的值是:fileName="C:\\abc1\\abc2\\filename".变成了双斜杠。然后我用这个方法也试了下:string filePath=@file+"\\"+filename.还是一样的结果。
求解啊!!!!!!为什么啊!!!!!
但是我用这个路径的调试时候发现系统给filePath的值是:fileName="C:\\abc1\\abc2\\filename".变成了双斜杠。然后我用这个方法也试了下:string filePath=@file+"\\"+filename.还是一样的结果。
求解啊!!!!!!为什么啊!!!!!
解决方案 »
- 求助:b/s转c/s困难吗
- 求一段 将GridView1保存为Excel的代码
- 服务器如何建立邮件系统?
- 接口中返回的object怎么转换成DataSet
- 请教一个消息传递的问题
- [**** winform 如何遍历 application 中已经分配内存资源的form (也就是被 new() 过的 )*****]
- 帮忙看看,找不到变量
- 请问下怎么判断2个pictureBox重叠?
- 哪位兄弟知道哪里有C#的网络编程(有实例)的电子书籍下载!(不要E版的)
- winform窗体的风格修改
- C#label的visible属性timer触发改变时 label的visiblechanged时间循环播放声音问
- C#如何获取客户端网卡地址??
fileName = fileName.Replace("\\","\");然后这个串不就是你想要的了嘛
转义字符
fileName = fileName.Replace("\\\\","\\");
fileName = fileName.Replace(@"\\",@"\");
string filePath=file+"\\"+filename;
或string filePath=file+@"\"+filename.
if (!File.Exists(filePath))
{
SqlConnection conn = new SqlConnection("server=" + local + ";database=Master;uid=" + username + ";pwd=" + pwd);
conn.Open();
SqlCommand cmd = new SqlCommand();
// SqlCommand cmd = new SqlCommand("backup database" + comboBox1.Text.Trim() + "to disk='" + filePath + "'",conn);
cmd.CommandText = "backup database " + comboBox1.Text.Trim() + "to disk='"+aa+"'";
cmd.Connection = conn;
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("备份成功!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.Close(); }
else
{
MessageBox.Show("文件已存在!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if (!File.Exists(filePath))
{
SqlConnection conn = new SqlConnection("server=" + local + ";database=Master;uid=" + username + ";pwd=" + pwd);
conn.Open();
SqlCommand cmd = new SqlCommand();
// SqlCommand cmd = new SqlCommand("backup database" + comboBox1.Text.Trim() + "to disk='" + filePath + "'",conn);
cmd.CommandText = "backup database " + comboBox1.Text.Trim() + "to disk='"+filePath+"'";
cmd.Connection = conn;
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("备份成功!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.Close(); }
else
{
MessageBox.Show("文件已存在!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
filePath = folderBrowserDialog1.SelectedPath.Replace(@"\\",@"\");
filePath += @"\" + textBox1.Text.Trim().ToString()+".bak";
这是因为\用于转义前缀以后,它自身只能以\\来表示了。