Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

C#
How to copy file in localserver share folde using c# .net windows application?


I want to copy file in to the local share folder using c# .net.
but its getting error:

C#
Could not find a part of the path 'xx.xx.x.xx\shared\abc_1.zip'


How to resolve this issue?
Pleas help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer

What I have tried:

C#
try
            {
                string ipAddress = txtIP.Text;
                //int port = int.Parse(txtPort.Text);
                for (int i = 0; i < arrayList.Count; i++)
                {
                    using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
                    {
                        zip.AddDirectory(arrayList[i].ToString());
                        //zip.Save(@"D:\abc" + "_" + (i + 1) + ".zip");
                        
                        zip.Save(@"D:\abc" + "_" + (i + 1) + ".zip");
                        fileName = @"D:\abc" + "_" + (i + 1) + ".zip";
                        fname = "abc" + "_" + (i + 1) + ".zip";
                        File.Copy(fileName, txtIP.Text + @"\shared\" + fname); //Error in this line.
                        MessageBox.Show(txtIP.Text + @"\\shared\" + fileName);
                        //Task.Factory.StartNew(() => SendFile(ipAddress, port, fileName, shortFileName));
                        MessageBox.Show("Files zipped");
                    }
                }
            }
Posted
Updated 27-Dec-16 21:28pm

1 solution

Quote:
Could not find a part of the path 'xx.xx.x.xx\shared\abc_1.zip'
Isn't it obvious?

You need to pass the correct path in order to access the file, otherwise it will always be a 404. I can suggest that you consider using Path.Combine[^] to remove maximum of errors while generating the paths for working.
C#
fileName = @"D:\abc" + "_" + (i + 1) + ".zip";
fname = "abc" + "_" + (i + 1) + ".zip";
File.Copy(fileName, txtIP.Text + @"\shared\" + fname); //Error in this 

Also, check again, whether the file exists there or not; the problem (IMO) is not with authentication, it says there is something extra or missing in the path.

c# - "Could not find part of the path" error when copying a file - Stack Overflow[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900