- protected void btnimport_Click(object sender, EventArgs e)
- {
- string filepath = FileUpload1.PostedFile.FileName;
- string path=filepath.Remove(filepath.LastIndexOf("//"));
- string filename=FileUpload1.FileName.Trim();
- bool checkspace = path.Contains(" ");
- string extName = "";
- extName = filepath.Substring(filepath.LastIndexOf(".") + 1);//获得文件的扩展名
- if (extName == "txt")
- {
- string BcpExec = "";
- string BcpExec1 = "";
- if (checkspace)
- {
- BcpExec = "subst w: /"" + path.Trim() + "/"";
- BcpExec1 = @"bcp xdcx..BadLoan in w:/" + filename + " ";
- }
- else
- {
- BcpExec = "cd";
- BcpExec1 = @"bcp xdcx..BadLoan in "+filepath+"";
- }
- //BcpExec += ds.Tables[0].Rows[i]["path"].ToString();
- BcpExec1 += " -c -t , -S10.0.74.15 -Usa -P1234";//组合bcp命令
- string msg=ExeCommand(BcpExec, BcpExec1);//执行bcp命令并显示操作结果
- private string ExeCommand(string commandText, string commandText1)
- {
- Process p = new Process();
- p.StartInfo.FileName = "cmd.exe";
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardInput = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.CreateNoWindow = true;
- string strOutput = null;
- try
- {
- p.Start();
- p.StandardInput.WriteLine(commandText);
- p.StandardInput.WriteLine(commandText1);
- p.StandardInput.WriteLine("exit");
- strOutput = p.StandardOutput.ReadToEnd();
- p.WaitForExit();
- p.Close();
- }
- catch (Exception e)
- {
- strOutput = e.Message;
- }
- return strOutput;
- }
调用bcp,网上说可以远程,试了下貌似不行,哎,咋办。
最新推荐文章于 2018-09-04 17:56:23 发布