Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
OpenFileDialog filedialog = new OpenFileDialog();
filedialog.ShowDialog();
TextBox1.Text = filedialog.FileName;


here i am uploading Excel file so before uploading it should be close so i want to close this file using C# Code behind
Posted
Updated 4-Dec-12 19:15pm
v2

The example you wrote only gets the name of the file. It doesn't upload or do anything else.

IMO what you should do is to check if the file is open or not before uploading it. One way is the try to get a read/write lock on the file when you open it. See File.Open Method (String, FileMode, FileAccess, FileShare)[^]

If you cannot open the file exclusively, then show a message to inform the user to close the file.
 
Share this answer
 
Comments
Espen Harlinn 11-Dec-12 17:49pm    
5'ed!
Wendelius 12-Dec-12 0:18am    
Thanks :)

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