我上传Excel文件所以在上传之前应该关闭所以我想使用C#Code后面关闭这个文件 [英] i am uploading Excel file so before uploading it should be close so i want to close this file using C# Code behind

查看:123
本文介绍了我上传Excel文件所以在上传之前应该关闭所以我想使用C#Code后面关闭这个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenFileDialog filedialog = new OpenFileDialog();
filedialog.ShowDialog();
TextBox1.Text = filedialog.FileName;





这里我上传Excel文件所以在上传之前应该关闭所以我想要使用C#代码关闭此文件



here i am uploading Excel file so before uploading it should be close so i want to close this file using C# Code behind

推荐答案

您编写的示例只获取文件的名称。它没有上传或做任何其他事情。



IMO你应该做的是在上传之前检查文件是否打开。一种方法是尝试在打开文件时获取文件的读/写锁定。请参阅 File.Open方法(字符串,FileMode,FileAccess,FileShare) [ ^ ]



如果你不能独占打开文件,那么显示一条消息通知用户关闭文件。
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.


试试这个..

http://stackoverflow.com/questions/1526685/c-怎样,我可以打开并关闭一个excel-workbook [ ^ ]
try this..
http://stackoverflow.com/questions/1526685/c-how-can-i-open-and-close-an-excel-workbook[^]


这篇关于我上传Excel文件所以在上传之前应该关闭所以我想使用C#Code后面关闭这个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆