Transferring files from one PC to another using C#? - c#

I'm using C#. I want to get the files that are on the server PC to my PC. Both PCs are connected through network.
I have given IP address of that PC in the path, but it's not copying the files to my folder. I'm using the following code, but it's not working:
File.Copy(Path.GetFileName(sourceFile), Path.GetDirectoryName(targetpath));
In sourceFile I have given IP address + folder path of the server PC and in the targetpath i have given the path of the folder of my PC to which I want to copy the files.

Wy do you use Path.GetFileName?
This function get only file name, not full path.
The signature of File.Copy(string sourceFileName, string destFileName) means, that you must use full path to both files.
This code works good:
File.Copy(#"\\server\folder$\test.txt", "test.txt");

Related

How to get server file path in folderbrowserdialog?

How can I show folder directory of the server file path (base on SQL server installation computer's folder path) on the client computer when I open FolderBrowserDialog.
I have the SQL server backup function and this function needs a directory for the backup location. So when I want to back up the database on server computer I need to show the server's director on FolderBrowserDialog.But now when I open the FolderBrowserDialog in the client, Its show the client directory.
Set the path via the FolderBrowserDialog.SelectedPath property

Unable to access network path using WMI managementClass.InvokeMethod

I have been trying to launch text pad installation from network path to a remote machine using WMI managementclass.InvokeMethod.
However several attempts have failed with
error code 1602
So I created a batch file containing script to launch installation executable from network path in a remote machine, and tried to invoke it with managementclass.InvokeMethod.
However, even this didn't work.
I tried the same by changing the executable from network path to remote machine C:\path.
And it worked!!!
But I want to launch the installation executable from a network path.
I would be grateful if somebody would help me.

ASP.NET FileUpload control retrieving server path not local path

I am currently having a problem when uploading a file using a file upload control in asp.net
I have published my page using IIS on a remote server and I am accessing that link on my local computer.
Currently when im trying to upload a file I get an error saying that path not found meaning its looking for the file path that is on my pc, on the server which of course doesn't exist.
How do I get this to get the path from my pc because im trying to copy/saveAs the file from my pc to the server.
My code:
String pathCombine = System.IO.Path.Combine(destinationDirectory, Path.GetFileName(file));
File.Copy(sourcePath, pathCombine);

How to find my exe is running in local or network shared folder

How to construct root path from registry editor when execute program in web server,while executing in local path i am getting as ""C:\Users\Desktop\SPHelper.exe" "%1"" but in web server i am getting in this format ""webserver\Dot net upload\SPHelper.exe" "%1".
How to construct root path in web server in complete format? for example("\\webserver\Dot net upload\SPHelper.exe""%1")
Hi We can use this to find the Location
System.Reflection.Assembly.GetExecutingAssembly().Location

crystal reports Issue in path file

After making a published version of asp.net webform application and uploading it to my clients server the application worked correctly.
But after time it showed this error:
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
at LogisticSystem.eokReports.ExportReportPage.GetReport()
in D:\Mostafa\LogisticSystem\LogisticSystem\eokReports\ExportReportPage.aspx.cs:line 390
this path is my local pc path
"D:\Mostafa\LogisticSystem\LogisticSystem\eokReports\ExportReportPage.aspx.cs" not a path at the clients server
It looks like you are trying to load a file that is not present at the clients server. Make sure that your report path is correct and the file exists. If "D:\Mostafa\LogisticSystem\LogisticSystem\eokReports\ExportReportPage.aspx.cs" not a path at the clients server is your error, then it's pretty clear that the file path you specify in your code does not exist on the server. Put the report file on the client's server and change your code to point to that file location instead of the location on YOUR machine.
Hope that helps,
Chris

Categories

Resources