"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message
I have a xml file on a shared folder(network, on NAS), which can be
write and read from any CE device that's attached to it.
I used WNetAddConnection3() to connect to the drive, which uses the SMB
protocol. This protocol supposely have a function
to do a lock on the file, but I can't find a API to do this. I have
search the newsgroups, but I can't find any for CE.
Any knows how to do this?
Be more specific about what you mean. "a lock on the file" isn't
descriptive enough. What do you wish to prevent or what happens when
you "lock" this file? If you just want to prevent other writers, you
should be able to open the file with no sharing enabled and I would
think that the network file system would do the right thing and prevent
other machines from accessing the file.
yes, that's what I meant. since the file can be read and write to by any
machine,
I need to actually have a lock to prevent any access to it by any other
machine,
when I upate the file, I need to a read, modify and write operation on
the file,
a simple open with no share will not work, because the read is done by
.net
XmlDocument.load(), which closes the file before the modify and write
operation.
Before I read this response, I was thinking about create a no share file
open using another file, and check this file before accessing another
file,
but that's kind of a hack. I was hopefully there is a more "elegant" or
"real" solution.
Like in the unix world, they have flock();(at least after googling,
that's what it looks like)
(and yes, I'm not a network programmer. pretty much just learn to connect
to network drives a few weeks ago)
Also, how can I detect if the network connected? couldn't find anything
on that either.
When you say "connected"? You can tell if the network itself is hooked
up and, as far as Windows CE can tell, working by using network calls
like GetAdaptersInfo(), which OpenNETCF's Smart Device Framework already
has wrapped for you. You want to see if media state connected is set.
Even if that happens, however, there's no way to tell that your file
open of a network shared file will work, other than attempting it.
That's pretty much the way that all network stuff works...
I am worrying the connection got disconnected, like someone yank the
cable
or power off the network device(NAS) while the application is running.
So I want to check it before I attempt a access to it and prevent any
problem as much as possible.