The following code is what I am trying to use to connect to and external server and get down to the subdirectories in the AppData folder.
string targetPath = #"\\externalServer\" + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Litera\\Customize";
While stepping through the program it comes to line 16 and fails stating "The given path's format is not supported." However, destFile shows "\\externalServer\C:\Users\username\AppData\Roaming\Litera\Customize\Customize.xml". To me the program is finding exactly the path I want. Can someone please help me resolve this problem?
File.Copy(sourceFile, destFile, true);
Related
When doing remote debugging. I share the directory say "d:\debug\app" on my remote debug machine to host machine.
On my host machine I setup the debug setting to use remote machine: "user#machine"
and start external program "\\machine\debug\app\start.exe"
When following program runs:
string codeBase = Assembly.GetExecutingAssembly().CodeBase;//codeBase="file://machine/debug/app/lib.dll"
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
Directory.SetCurrentDirectory(Path.GetDirectoryName(path));//Path.GetDirectoryName(path)="\\debug\\app"
getting error:
System.IO.DirectoryNotFoundException was unhandled
Message="Could not find a part of the path '\\\\machine\\debug\\debug\\app'."
Looks like the Directory.SetCurrentDirectory() is taking the shared folder as root. and trying to do "\machine\debug" + "debug\app"
How to fix this?
It's not a problem of formate.
There is a similar question here: How do I convert a UNC path back to an absolute local path on the remote PC?
But, the author give a self code solution. I would like something easy with existing API and tools.
So this is my code, i basically copied and pasted from SharpSSH website.
Sftp oSftp = new Tamir.SharpSsh.Sftp(_ftpURL, _UserName, _Password);
oSftp.Connect(_Port);
oSftp.Put(LocalDirectory + "/" + FileName, _ftpDirectory + "/" + FileName);
oSftp.Close();
When i run this, i get a "first chance exception" on oSftp.Connect(_Port)
A first chance exception of type 'Tamir.SharpSsh.jsch.JSchException' occurred in Tamir.SharpSSH.dll
Does anyone experienced with SharpSSH have any idea why this is happening? I have also tried uploading files to the server using Rubex but it gave me the same error.
First you need to pass only folder path of server and do not specify file name in that path.
oSftp.Put(LocalDirectory + "/" + FileName, _ftpDirectory);
and also make sure you have added below packages from nuget
Install-Package DiffieHellman
Install-Package Org.Mentalis.Security
just check your path of file and path where you want to upload on sftp.
example:
Sftp sftp=new Sftp("host","username","pass");
sftp.Connect();
sftp.Put("path of your local file","path to upload file on sftp server");
sftp.Close();
I am struggling with how to make my app work when deployed - it keeps saying the file is invalid no matter what I do:
What I have now is:
Data Source="\MyDb.sdf"
The DB should be in the directory where the executable is located.
You probably need to use an absolute path to access the file.
var pathToExe = System.Reflection.Assembly.GetExecutingAssembly().Location;
var path = Path.GetDirectoryName(pathToExe);
var pathToDb = Path.Combine(path, "MyDb.sdf");
pathToDb should now be an absolute path to your database object, assuming it is always in the directory of the executing assembly.
this is my scenario: I have an executable file that convert html files to pdf.
This exe work only if you start it from its folder.
Example: the exe is in C:\HtmlToPdf, so, in the prompt I will do this:
C:\> cd HtmlToPdf
C:\HtmlToPdf> htmltopdf.exe htmlFile pdfFile
So, there is a way to do this in c#? Because I tried this:
FileInfo htmlInfo = new FileInfo(executablePath + #"\" + filename);
var procInfo = new ProcessStartInfo("wkhtmltopdf.exe",htmlInfo.FullName + " " + htmlInfo.FullName.Replace(".html",".pdf"));
procInfo.WorkingDirectory=executablePath;
procInfo.UseShellExecute = false;
Process.Start(procInfo);
But it doesn't work.
wkhtmltopdf's documentation/wiki states that it will struggle to find a file if you use its full path. You need to append file:/// to the beginning of the file name
Note that on Windows, you can't use absolute path names with drives for HTML files at the moment:
wkhtmltopdf d:\temp\x.html x.pdf
will fail. You need to rather use file:/// URLs:
wkhtmltopdf file:///d:/tmp/x.html x.pdf
This answer may help in the appending
From where you are calling the EXE .. .whether its Windows Form application or Webforms....
If its windows forms it will work
else
if its Webforms like asp.net you have to change the properties of IIS Server to start the exe
Because due to some security reasons microsoft will not allow you to start the process class from IIS server... but the same code will work from Visualstudio ..
Here is my code
To get Current Exe Executable path
string sCurrentPAth = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Process.Start(#"E:\Debug\MyExe.exe", "arg1 arg2 arg3");
Its Working Correctly .....
Hello I am attempting to copy a file over to a shared network but I continue getting the error The filename, directory name, or volume label syntax is incorrect. Could someone please catch what I am doing incorrectly. Also my Application is running using ASP.NET MVC3, Thanks!
copy code
File.Copy(#path, #Properties.Settings.Default.SharedMappedOutput);
The path is a parameter: C:\log\12345.pdf
Properties.Settings.Default.SharedMappedOutput Path: \\vfler_xx\evl_xx\VT\ .
What I want to accomplish: I want to copy the file from Path (filename) to SharedMappedOutput (directory)
Extra information
Windows Server 2008 R2
IIS 7.5
ASP.NET MVC3 C#
EDIT
I have changed my code with the help of #Steve, but now it is saying I do not have access to a path that I did not specify.
String dest_path = Properties.Settings.Default.SharedMappedOutput;
File.Copy(#path, Path.Combine(dest_path, Path.GetFileName(path)));
ERROR
Access to the path 'c:\windows\system32\insetsrv\12345.pdf' is denied
I did not specify this path, I am not sure why it is trying to access this path.
Link to the new problem
https://stackoverflow.com/questions/16179585/iis-acccess-to-the-path-c-windows-system32-inetsrv-12345-pdf-is-denied
Thank you. Please let me know if there is any questions or misunderstanding in the question. Thanks in advance again.
File.Copy doesn't copy a directory to another directory, but just a filename.
Your c:\log seems to be just the name of a directory and as stated by the documentation at MSDN this doesn't work
To copy all the file in the source path you could write this
string destPath = Properties.Settings.Default.SharedMappedOutput;
foreach (string aFile in Directory.GetFiles(path, "*.*"))
File.Copy(aFile, Path.Combine(destPath, Path.GetFileName(aFile)));
EDIT
Seeing the comment about the real source name then the answer is still partially valid because also the destination should be a filename and not a directory. So the answer becomes
string sourceFile = #"C:\log\12345.pdf";
string destPath = Properties.Settings.Default.SharedMappedOutput;
File.Copy(sourceFile, Path.Combine(destPath, Path.GetFileName(sourceFile)));
This has something to do with using a UNC path if I remember correctly. Map the share as a mapped drive and it will work like a charm.
here is an example on mapping the unc path to a mapped drive.
http://www.codeproject.com/Articles/6847/Map-Network-Drive-API