追加文本文件内容时报“文件正由另一进程使用,因此该进程无法访问该文件”
求解:在追加文本文件内容时报:“System.IO.IOException: 文件“D:\WEBROOT\IntegrateOfficeSystem\WEB_TwoDimensionalCode\Log\APIPlatform\TwoDimensionalCode\FreezeChargebackFailure\2012-08-17.txt”正由另一进程使用,因此该进程无法访问该文件。 在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) 在 System.IO.StreamWriter.CreateFile(String path, Boolean append) 在 System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) 在 System.IO.StreamWriter..ctor(String path, Boolean append) 在 System.IO.File.CreateText(String path) 在 IntegratedOfficeSystem.Tool.FileOperations.GetCreateFile(String FileName) 位置 D:\Work\IntegratedOfficeSystem\IntegratedOfficeSystem\IntegratedOfficeSystemTool\FileOperations.cs:行号 27 在 CreateLog.GetReturnGenerateLog(String Content, Int32 GenerateType, Int32 DirType) 在 OperatingTDC_TwoDimensionalCode.GetSendTwoDimensionalCode(String XML)
/// <summary> /// 追加文件 /// </summary> /// <param name="Path">文件路径</param> /// <param name="strings">内容</param> public static void FileAdd(string Path, string strings) { StreamWriter sw = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(Path)); sw.Write(strings); sw.Flush(); sw.Close(); sw.Dispose(); }