views:

408

answers:

2

In my C# windows application, I am exporting sql server data to excel on remote drive. But it is too slow. However, if I export data to excel in the local drive, it is fast.

How can I increase the time if I want to export data to remote drive?

Thanks in advance...

+2  A: 

If it is an option for you, export to the local drive and then copy/move the exported file to the remote drive.

JonathanK
+1  A: 

Export to a temp folder on the local machine, copy it to the network and then delete the file from the temp folder. You could even do the copy and delete on a separate thread so the UI's not blocked.

Chris Conway
this seems to be a fantastic solution...thanks..
Manish Gupta
how's about marking my answer as the solution?
Chris Conway
I have created a temporary excel file and then copied to the destination. But when I try to delete the temporary file, it throws exception that the file is in use.
Manish Gupta
can you post the code?
Chris Conway
Here is the code:File.Copy(sourceFile,destFile,true);File.Delete(sourceFile); //Here it is throwing the exception
Manish Gupta
perhaps try File.Move(sourceFile, destFile); make sure to do this first though:if (File.Exists(destFile)) File.Delete(destFile);
Chris Conway
I have already tried [File.Exists(destFile)] but it does not work.It seems that after copying the file the source file is not released for some time.So, I added following code...System.Threading.Thread.Wait(1000);File.Delete(sourceFile);Then it worked. But it blocks the UI for 1sec.Is there other method I can use?I also cannot use File.Move(sourceFile,destFile) because if the destination already consists similar filename, then it does not work.Thanks in advance...
Manish Gupta
right, i'm saying get rid of file.copy and then file.delete() and just do this: if (File.Exists(destFile)) File.Delete(destFile); File.Move(sourceFile, destFile); This will delete the file first from the destination directory and then move the new file there. This way you don't need to worry about copying the file, waiting one second and then deleting it.
Chris Conway
Thanks...It worked.
Manish Gupta
no problem, glad to help.
Chris Conway