|
Is there anyway to do this without closing/reopening the file?
I found this in some code I wrote a few years, and after cringing and hitting google, failed to do so.
m_fsXMLLib = new FileStream(m_fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
m_fsXMLLib.Close();
m_fsXMLLib = new FileStream(m_fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
My intent is to keep anyone from trying to read the file while it's being written and in an inconsistent state. After saving the file, I want it kept open to prevent anyone else from being able to modify it while letting them have read only rights.
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
Hi Dan,
interesting question.
IMO a pure .NET solution does not exist. This is what I would try:
- create the FileStream with Share.None
- write and flush the data
- now P/Invoke to CreateFile, specify Share.Read and a zero FileMode (which .NET compiles but refuses to run) as explicitly allowed here[^]
- finally close the original FileStream.
That may run all right and yield a file readable for others.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks, I'll give it a shot when I get back into the office on tuesday.
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
I am writing a web application that I want to use windows authentication for. The only problem is that the users using it may not always be running it from there own machine. I want to check the roles for the current windows user and if they have the required role take them directly into the application. If the current user does not have the required role I will take them to a sign-on page so they can enter their windows user i.d. and password. Then I will check if that user has the required role. The problem is that I can only find a way to check the roles for the current windows user.
Is there a way to validate the user that signs in to the application rather than the windows user and check the roles or groups they are in?
Thank you
Marty
|
|
|
|
|
Use the techniques from this article to impersonate the user given their username and password. Create a new System.Security.Principle.WindowsIdentity object from the token you'll get back from LogonUser. Use my code from this post, where currentPrinciple is the WindowsIdentity you created
|
|
|
|
|
Thank you, I will try this as soon as possible.
Marty
|
|
|
|
|
Thank you this helped greatly.
Marty
|
|
|
|
|
Hi, i want to create an application that can be loaded into anyone computer.. But the database has to be consistent, so i was thinking of using my web server mysql database.
but how do i use the database from the application i created?
|
|
|
|
|
Use a webservice to communicate with the database and have some sort of authentication system for your client.
|
|
|
|
|
can give me some idea of what web service?
|
|
|
|
|
|
dont quite understand..
anyway can use mysql connection string? den replace localhost with my server ip?
|
|
|
|
|
check out this site[^] as it's the leader with connectionstrings, but yes that's pretty much it.
|
|
|
|
|
how do work program database in c# with sql server
|
|
|
|
|
Go buy a book on basics, a forum post can't nearly cover this topic.
|
|
|
|
|
|
Hi There,
Any code snippet in C# on how i can insert a string value in a ByteA column in PostGreSQL ?
Reagrds,
X
Yeee
|
|
|
|
|
in VB . a class can have constructor and funstion or sub. so how to create a function return a value in C# class ?
|
|
|
|
|
you lazy little *&^@!
use google[^]
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: you lazy little *&^@!
lol! +5
|
|
|
|
|
Hi,
both subroutines and functions are called methods in C#; they may or may not return one value or reference, depending on the return type in the declaration. Same as in C, C++, Java, and a lot of other languages (except they often are called functions, with or without a return value).
I suggest you buy and study a tutorial on C# so you can reach structured and illustrated knowledge in minimal time.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Seriously, this is a C# 101 class question. Pickup a beginners book on C# and work through it. It'll answer just about all of your basic questions like this.
|
|
|
|
|
Epic fail. How can you be asking about events first and only after that want to return values? Obviously something is wrong here. I think you're some gold member who thinks it's funny to ask crazy questions on purpose. And if that's true, well, ok it would be funny I suppose.
|
|
|
|
|
I have searched high and low for an answer to this one. I'm sure someone has
run into a similar situation.
Basically, I set up a serial port with a ReadTimeout of 10 seconds; open it; send a "command"
character to a serially attached device and expect an answer within this period of time.
If data is received, the serialPort_DataReceived event handler fires and reads the data.
However, I want to be able to notify the operator of a problem, should the external
device not reply within 10 seconds. This could indicate the device is not attached or
not powered up.
Appreciate the help,
Steve.
|
|
|
|
|
thompsons wrote: I have searched high and low
Not high and low enough then. It took me 10 seconds to find this[^]
The SerialPort class provides a timeout mechanism on its Read methods. When the read timeout is exceeded, a TimeoutException gets thrown.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|