我正在开发一个应用程序,它需要删除文件,无论其他进程是否正在使用它
请考虑以下代码段.
using System;
using System.IO;
namespace DotNet_Concepts.File_Operation
{
class Deleting_File_Which_Is_In_Use
{
static void Main(string[] args)
{
StreamReader lclFileStream = null;
string lclFileName=string.Empty;
try
{
lclFileName=@"E:\Visual Studio 2008 Projects\DotNet Concepts\DotNet Concepts\Local Files\Garbage.txt";
if (File.Exists(lclFileName))
{
lclFileStream = new StreamReader(lclFileName);
if (lclFileStream != null)
{
//Doing some operation
}
//Deleting the file before closing the stream
File.Delete(lclFileName);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.StackTrace);
}
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在删除同一进程使用的文件.是否可以删除该文件
谢谢,阿米特沙阿
我是.NET的新手,我想开发一个向单个HTTP请求发送多个HTTP响应的应用程序.
有没有办法可以在服务器上存储HTTP Handler,可以在需要时使用.
提前致谢.
阿米特沙阿
我正在创建一个需要将c#对象转换为XML的应用程序.
我正在使用XML Serializer类来实现这一点.这是代码片段:
public class Anwer
{
public int ID { get; set; }
public string XML { get; set; }
public Anwer(int ID, string XML)
{
this.ID = ID;
this.XML = XML;
}
public Anwer() { }
}
Run Code Online (Sandbox Code Playgroud)
这是主要功能:
string AnswerXML = @"<Answer>1<Answer>";
List<Anwer> answerList = new List<Anwer>();
answerList.Add(new Anwer(1,AnswerXML));
AnswerXML = @"<Answer>2<Answer>";
answerList.Add(new Anwer(2, AnswerXML));
XmlSerializer x = new XmlSerializer(answerList.GetType());
x.Serialize(Console.Out, answerList);
Run Code Online (Sandbox Code Playgroud)
输出是:
<?xml version="1.0" encoding="IBM437"?>
<ArrayOfAnwer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="h
ttp://www.w3.org/2001/XMLSchema">
<Anwer>
<ID>1</ID>
<XML><Answer>1<Answer></XML>
</Anwer>
<Anwer>
<ID>2</ID>
<XML><Answer>2<Answer></XML>
</Anwer> …Run Code Online (Sandbox Code Playgroud)