如何使用通用处理程序(ASHX)编辑(.txt文件)?

出于某种原因,我正在使用Asp.net通用处理程序(ASHX)来编辑(.txt文件)。
我尽一切努力只是编辑一个令人兴奋的.txt文件的文本。我总是收到错误消息

该进程无法访问文件'E:bla bla bla \ Home_0.txt',因为该文件正在被另一个进程使用。

此消息继续弹出,尽管我没有打开物理文件或以任何其他方式使用它!

我的尝试代码如下所示

            string ShortFilePath = "Pages_Texts/";
            FullFilePath = ShortFilePath + "Home_" + Text_Naming_Order + ".txt";
            string appPath = context.Request.PhysicalApplicationPath;
            string ServerPath = appPath + FullFilePath;

            context.response.contenttype = "application/octet-stream";
            context.Response.WriteFile(ServerPath);

            //byte[] rawBytes = File.ReadAllBytes(ServerPath); // Insert loading file with IDDownload to byte array
            //context.Response.OutputStream.Write(rawBytes,rawBytes.Length);

            ////var fs = File.AppendText(ServerPath);
            //byte[] b = File.ReadAllBytes(ServerPath);
            ////UTF8Encoding temp = new UTF8Encoding(true);
            ////fs.Write("ffffffffffffffff",10);
            //File.WriteAllBytes(ServerPath,b);


            using (Stream stream = new FileStream(ServerPath,FileMode.Open))
            {
                stream.Dispose();
                using (var writer = new StreamWriter(context.Server.MapPath(FullFilePath),false))
                {
                    //File.Delete(context.Server.MapPath(FullFilePath));
                    //File.WriteAllText(context.Server.MapPath(FullFilePath),RawHtml);
                    writer.WriteLine(RawHtml);
                    writer.Dispose();
                    //writer.Flush();
                    writer.Close();
                }
                msg = msg + "\n The text File saved successfully";
            }
Lee_Ryan 回答:如何使用通用处理程序(ASHX)编辑(.txt文件)?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2407454.html

大家都在问