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

I would like to copy an excel file into the server but I couldn't do it...There is no any error but it doesn't copy that.

C#
void FileCopy()
{
  FileInfo pathinfo = FileInfo(Path);
  if(!PathInfo.Exists)
  {
    PathInfo.CopyTo(string path);
   }
}


Is there anyone who can help me here?

Regards

Haluk
Posted
Comments
Sandip.Nascar 9-Oct-12 4:09am    
Did you check the path, whether it actually exists? Debug the code and see, if debugger hits the line PathInfo.CopyTo(string path)
haluk_78 9-Oct-12 4:17am    
Yes,it is already exists...

I suspect that you need to look at your variables:
Path is not the same as path
pathinfo is not the same as PathInfo

And string path creates a new variable, and sets it to null...
C#
PathInfo.CopyTo(string path);
 
Share this answer
 
Comments
haluk_78 9-Oct-12 4:29am    
This one is the whole code...:

void FileCopy()
{
FileInfo pathinfo = new FileInfo(Server.MapPath(@"MATBUEVRAK/125/EVRAKLAR.xls"));
if (!pathinfo.Exists)
{
File.Copy(Server.MapPath(@"MATBUEVRAK/EVRAKLAR.xls"), pathinfo.FullName);

}


}
OriginalGriff 9-Oct-12 4:35am    
That give you two things to check:
1) Does the source file exist, relative to the ASPX page you are executing?
2) Does the destination file exist, relative to the ASPX page? Because if it does, your code won't copy anything.
haluk_78 9-Oct-12 4:52am    
Yes, it does... Normally, that code block is working but it doesn't work in the server...
OriginalGriff 9-Oct-12 5:06am    
Check permissions - in the server it may be running as a user that does not have write permissions to the folder.
If you use PathInfo.Copy, you are copying the file directories along with the files and sub directory. As per your requirement, you need to copy an excel file.

So, use File.Copy

PathInfo.Copy should work, but I guess, you have specified the filename within the path.

http://msdn.microsoft.com/en-us/library/cc148994.aspx[^]

Hope this works.
cheers
 
Share this answer
 

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