I`m getting an ArgumentException from the following code:
string strPath="C:\somename.xls";
startPath=System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
filePath = System.IO.Path.Combine(startPath, strPath);
I found this code on Stack Overflow. Link: C#:Copy protected worksheet to another excel file I don't exactly know what it is. Please tell me what it is. This code I'm building into an exe.
Lastly, I need to Copy one worksheet to another file.
What`s wrong am I doing? I deploy this in server.
what that code appears to do, is it gets your working directory(wherever the exe
associated with your code is), and combines it with "C:\\somename.xls"
(which doesn't make sense.)
I think you might have intended something like
string strPath=@"somename.xls";
so assume you're running your application from
"C:\Users\owner\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug"
what that code would do is set filePath
to
"C:\Users\owner\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\somename.xls"
the first thing I saw was
string filePath="C:\somename.xls";
\
is a special character, for determining other characters. for instance '\n'
is a newline. '\\'
is the actual backslash.
so, you want to escape your \
with another \
string filePath="C:\\somename.xls";
or make it a literal string by putting a @
in front of it.
string filePath=@"C:\somename.xls";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With