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 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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.
Here is the code: File.Copy(sourceFile,destFile,true); File.Delete(sourceFile); //Here it is throwing the exception
perhaps try File.Move(sourceFile, destFile); make sure to do this first though:if (File.Exists(destFile)) File.Delete(destFile);
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...
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.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.