0

I'm making a small application that have to take all the files from a shared folder and copy them in the current folder(the once from where the application it's runned). One month ago this code was fine:

            string seprin_address = @"\\PC-SEPRIN\2port\";
            SimpleCopy(seprin_address);

    public void SimpleCopy(string sourcePath){
    try{
        string fileName = ""; 
        string targetPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
        bool path = false;
        string real_target = "";
        for(int i = 0; i < targetPath.Length; i++){
            if(targetPath[i] == 'C'){
                path = true;
            }
            if(path){
                real_target += targetPath[i];
            }
        }
        // Use Path class to manipulate file and directory paths. 
        string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
        string destFile = System.IO.Path.Combine(targetPath, fileName);


        // To copy a folder's contents to a new location: 
        // Create a new target folder, if necessary. 
        /*if (!System.IO.Directory.Exists(targetPath))
        {
            System.IO.Directory.CreateDirectory(targetPath);

        }*/

        // To copy a file to another location and  
        // overwrite the destination file if it already exists.
        //System.IO.File.Copy(sourceFile, destFile, true);

        // To copy all the files in one directory to another directory. 
        // Get the files in the source folder. (To recursively iterate through 
        // all subfolders under the current directory, see 
        // "How to: Iterate Through a Directory Tree.")
        // Note: Check for target path was performed previously 
        //       in this code example. 
        if (System.IO.Directory.Exists(sourcePath))
        {
            string[] files = System.IO.Directory.GetFiles(sourcePath);

            // Copy the files and overwrite destination files if they already exist. 
            foreach (string s in files)
            {
                // Use static Path methods to extract only the file name from the path.
                fileName = System.IO.Path.GetFileName(s);
                destFile = System.IO.Path.Combine(targetPath, fileName); 

                System.IO.File.Copy(s, destFile, true);
            }
        }
        else
        {
            MessageBox.Show("Error");
        }

        // Keep console window open in debug mode.
        }
        catch(Exception e_p){
            lbabel.Text = e_p.Message;
        }
    }

Now i get the "URI not supported error" when the file.copy it's called. I think its supernatural but if you have any other ideas i'm all ears.

4

2 回答 2

0

我会找出不支持的 URI 是否在抱怨源或目标。我还将检查以确保正在运行的用户具有对相关目录的权限。用户权限是否已更改?我曾经有过在设置了用户的计划任务中工作的情况,后来更改了用户的密码,但没有在计划任务中更改密码。如果将其编写为针对特定用户的服务,情况也是如此。

于 2013-11-13T15:13:05.510 回答
0

正如您所说的它在一个月前工作正常,可能有两种可能性限制您访问路径。

1.远程PCHostname PC-SEPRIN可能已更改。请检查远程PC主机名。
2.正确检查共享文件夹2port路径。

如果有人更改共享文件夹名称或将其删除,您将无法访问它。并请检查您是否有权访问它。

于 2013-11-13T15:45:16.413 回答