无法删除C#.net中的文件 [英] Can not delete File in C#.net

查看:53
本文介绍了无法删除C#.net中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...
我的问题是我想从一个文件夹中删除一个文件.文件的大小最初是0字节.但是在我的代码中它显示了27个字节(通过此代码File_name.Length).这就是为什么我无法删除该文件的原因. 背后的原因是什么?怎么删除那个?

谢谢您

Hi Every one...
My problem is that I want to delete a file from one folder.Originally the size of the file is 0 byte. but in my code it shows 27 bytes(by this code File_name.Length ). that''s why i can not delete that file.
what is reason behind it ? and how can i delete that one?

Thanking You

推荐答案

System.IO.File.Delete(File_name);
那是命令,而不是File_name.Delete()或类似的东西...
System.IO.File.Delete(File_name);
that''s the command, not File_name.Delete() or something like that...


Krushna,

您的代码是完美的,除非满足以下条件:

Hi Krushna,

Your code is perfect, except for this if condition:

if (Spath2.Length== 0)



您正在此处检查Spath2字符串的长度.它是27个字符的长度.

我再次再次. 27不是文件大小,它是字符串Spath2中的字母/字符数.

要检查文件大小,您必须执行以下操作.



You are checking the length of Spath2 string here. It is 27 characters in length.

Again I repeat. 27 is not the file size, it is the number of alphabets/characters in the string Spath2.

To check for the file size, you have to do something like this.

 string Spath2=Spath +@"\"+fj;   
FileInfo objFileInfo=new FileInfo(Spath2);
if (objFileInfo.Size == 0)



检查并让我知道.



Check and let me know.


文件大小现在为0byte.它的sisz必须是27bytes ..请再解释一下.您必须通过代码将其删除?
File size is now 0byte. its sisz must be 27bytes..could be please explain a bit more. you have to delete it through code?


这篇关于无法删除C#.net中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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