簡體   English   中英

如何從共享文件夾或另一台服務器復制和粘貼文件?

[英]How to copy and paste the files from shared folder or from another server?

我正在創建應用程序。 在那,我把組合框,組合框由應用程序號填充。 來自數據庫。 在選擇組合框時,網格會將該文件填充到驅動器中另一台計算機中。 //user/public/af001/edit/test.JPEG一樣,在網格中,我將下載鏈接放在特定行上,以便在機器中下載該文件,但是問題是當我下載該文件時,我沒有得到//user/public/af001/edit/test.JPEG

            if (e.Column Index == 0)
            {
                int row;
                //Get the row index
                row = e.Row Index;

                string old Path = @"~\\Users\Public\AS\AFS1402190001\Edit\test.JPEG";
                string new path = @"E:\example\";
                string new File Name = "new file name";
                File Info f1 = new File Info(old Path);
                if (f1.Exists)
                {
                    if (!Directory.Exists(new path))
                    {
                        Directory.Create Directory(new path);
                    }
                    f1.Copy To(string.Format("{0}{1}{2}", new path, new File Name, f1.Extension));
                }
             }

你能告訴我問題是什么嗎?

感謝幫助。

問題在這一行:

   string.Format("{0}{1}{2}", new path, new File Name, f1.Extension);

看來您沒有建立正確的文件補丁。 嘗試使用System.IO.Path.Combine組合目錄和fileName。 就像是:

System.IO.Path.Combine(dirPath, string.Format("{0}.{1}", fileName, extension));

當然,您可能要確保路徑/文件名沒有無效的字符,可以使用System.IO.Path.GetInvalidFileNameChars()System.IO.Path.GetInvalidPathChars()來獲取所需的非法字符避免。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM