重新编写文本文件(ReWrite text file)
如何重写文本文件(在指定位置)并锁定他?
要重写,需要先阅读然后再编写。 - 这很容易 - 但我需要将make文件锁定到整个重写中的所有其他进程。
我有方法。
public bool AccessBridge() { try { fs = new FileStream("bridge.ini", FileMode.Open, FileAccess.ReadWrite); sr = new StreamReader(fs); sw = new StreamWriter(fs); return true; } catch (IOException ioe) { return false; } }
然后再测试一部分:
string precteno = sr.ReadToEnd(); //Some modify string //now I need delete whole text from file sw.Write(precteno);
有任何想法吗? 我已经处理了第二天晚上。
How to rewrite text file (at specificated position) and lock him?
For rewrite it need read and then to be written. - it is easy - but I need make file to be locked to all other process in the whole rewriting.
I have method.
public bool AccessBridge() { try { fs = new FileStream("bridge.ini", FileMode.Open, FileAccess.ReadWrite); sr = new StreamReader(fs); sw = new StreamWriter(fs); return true; } catch (IOException ioe) { return false; } }
Then another test part:
string precteno = sr.ReadToEnd(); //Some modify string //now I need delete whole text from file sw.Write(precteno);
Any ideas? I have deal with it 2nd night.
原文:https://stackoverflow.com/questions/33794238
最满意答案
最后,我决定采用不同的方法,并使用WCF身份验证服务在不同的客户端之间共享,如本文演练:使用ASP.NET应用程序服务中所述 。
这是一个更简洁的解决方案,而不是试图让Web矩阵直接从WPF项目内部工作。
In the end I decided to take a different approach and use a WCF authentication service to share between my different clients, as outlined in this post Walkthrough: Using ASP.NET Application Services.
This was a neater solution than trying to get web matrix to work directly from inside a WPF project.
相关问答
更多-
当然, WebMatrix.WebData的代码是开源的 这里是WebSecurity类的链接 - https://github.com/aspnetwebstack/aspnetwebstack/blob/master/src/WebMatrix.WebData/WebSecurity.cs Sure, the code for WebMatrix.WebData is open source Here is the link to WebSecurity class - https://github.c ...
-
ASP.Net附带的WebSecurity(以上代码中使用的)在代码中嵌入了一些Microsoft T-SQL语法。 MySQL语法和MSSQL之间几乎没有什么区别,这可能是错误的原因。 从显示的错误中,我可以看到WebSecurity中的CreateUserAndAccount方法以某种方式尝试执行T-SQL语句.... [UserId] FROM [UserTable] WHERE (UPPER([UserName]) = UPPER('user'))但是,虽然这可以在MSSQL中使用,但方括号"["和 ...
-
对我来说,这个错误是因为我从MVC 4更新到MVC 5后没有安装Microsoft.AspNet.WebHelpers。它是通过安装NuGet包来修复的 Install-Package -Id Microsoft.AspNet.WebHelpers For me this error was because I did NOT have Microsoft.AspNet.WebHelpers installed after updating from MVC 4 to MVC 5. It was fix ...
-
这是令人尴尬的。 起初,我错过了App.config中的配置部分:
... -
UnitTest中WebSecurity.Login简单成员资格的错误(Error in UnitTest for WebSecurity.Login simple membership)[2022-04-24]
WebSecurity.Login 实际上在场景后面使用FormsAuthentication.SetAuthCookie ,因为FormsAuthentication.SetAuthCookie使用旧的httpcontext api,因此即使使用moq httpcontext也会抛出异常。 http://forums.asp.net/t/1871234.aspx 所以解决方案是依赖注入。 FormsAuthentication.SetAuthCookie使用Moq进行模拟 http://forums.as ... -
什么版本的MVC? 什么版本的Visual Studio? 这是一个旧项目还是新项目。 如果它是一个相对较新的项目,使用您想要的身份验证创建新的shell解决方案可能更容易 - 然后从旧解决方案中提取您的模型,控制器和视图。 如果它是VS2013 MVC 5项目,你可能会错过 public partial class Startup 在应用程序的根目录中的类。 如果您创建一个新的空解决方案,您可以比较那里的内容和您的内容。 但是......你需要先阅读Simplemembership .... http: ...
-
我正在尝试在.Net桌面应用程序中实现WebMatrix.WebData.WebSecurity()方法 忘掉它。 成员资格提供程序与ASP.NET上下文紧密结合,不打算在桌面应用程序中使用。 它取决于HttpContext,cookies等......在桌面应用程序中不存在。 您可以做的是定义一个可以在桌面应用程序中直接使用的可重用服务层,然后让ASP.NET成员资格提供程序的实现调用此服务层的方法,从而在两者之间重用相同的功能。 I am trying to implement the WebMatri ...
-
在WPF应用程序中使用WebMatrix.WebData.WebSecurity(Using WebMatrix.WebData.WebSecurity in a WPF application)[2022-05-18]
最后,我决定采用不同的方法,并使用WCF身份验证服务在不同的客户端之间共享,如本文演练:使用ASP.NET应用程序服务中所述 。 这是一个更简洁的解决方案,而不是试图让Web矩阵直接从WPF项目内部工作。 In the end I decided to take a different approach and use a WCF authentication service to share between my different clients, as outlined in this post Wa ... -
使用表单身份验证在ASP.Net中的Web服务器上的权限(Rights on web server in ASP.Net using forms authentification)[2022-03-22]
问题是由我们的第三方报告引擎引起的。 引擎在运行时动态编译dll,然后调用CodeDomProvider.CompileAssemblyFromSource([...])。 据我所知,这是导致问题的原因。 第三方提供编译到dll的选项,并将其作为参考包含在内。 我们用过这个解决方案 The problem was caused by our 3rd party reporting engine. The engine was dynamically compiling a dll at runtime th ... -
VNC控制WPF应用程序(VNC control for WPF application)[2023-04-22]
我建议在WPF应用程序方法中使用WinForms控件。 这真的很简单。 将WindowsFormsIntegration引用添加到您的项目 在您的XAML中添加一个WinForms集成元素:将WinForms控件添加到代码隐藏中的该元素: host.Child = new WinFormsControl(); I recommend going with the WinForms control in a WPF applications ...