hi there,
i have a question in coping a file to machine in the network
i use the below code

public string UploadFile(string ID,string Phase,string source,string fileName)
        {
            string path = @"\Server-003\F\Details\Reports\" + ID + @"\Phase" + Phase + @"\Proposal";
            Directory.CreateDirectory(path);
                       
            //string folderPath = path.Substring(0,slashIndexLast);

            string[] files = Directory.GetFiles(path);
            for (int r = 0; r < files.Length; r++)
            {
                int dotIndexLast = files[r].LastIndexOf(".");
                int slashIndexLast = files[r].LastIndexOf("\\"); 
                
                string fileWithName = files[r].Substring((slashIndexLast+1), ((dotIndexLast-1) - slashIndexLast));
                if (fileWithName.Equals(fileName))
                    File.Delete(files[r]);
            }

            int sdot = source.LastIndexOf(".");
            string sourceExt = source.Substring(sdot,(source.Length-sdot));
            
            string copyFile = path +@"\"+fileName+""+ sourceExt;
            File.Copy(source, copyFile);
            return copyFile;   
        }

but when i run the code
it copies the fiel in the c drive creating the folder path as " \Server-003\F\Details\Reports\" + ID + @"\Phase" + Phase + @"\Proposal "

how do i give the path to the machine i want to copy the files

please can some one give me some guidence
thanxxxxx

You were almost there. In the windows environnement, another machined is defined by "\\". Which means your path would be "\\Server-003\".

The path you created means ("\Server-003\F\Details\Reports\"), go at the root level ('/') and create the folder structure. Note that if you had no slashes, it would mean, from current directory, and as I said, double black slashes ('\\') means completly another environment. If you take a quick pick on a computer of your network, it's probaby gonna show as either \\192.168.0.x or \\Daddy-PC.

Hope this helps!

You were almost there. In the windows environnement, another machined is defined by "\\". Which means your path would be "\\Server-003\".

The path you created means ("\Server-003\F\Details\Reports\"), go at the root level ('/') and create the folder structure. Note that if you had no slashes, it would mean, from current directory, and as I said, double black slashes ('\\') means completly another environment. If you take a quick pick on a computer of your network, it's probaby gonna show as either \\192.168.0.x or \\Daddy-PC.

Hope this helps!

wow
thanks

wow
thanks

No problem ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.