NetFileEnum

P

phancey

I am using NetFileEnum like this but the pathname doesn't actually give
me the filename - how do I get the actual filename?
:

[DllImport("netapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
static extern int NetFileEnum(
string servername,
string basepath,
string username,
int level,
ref IntPtr bufptr,
int prefmaxlen,
out int entriesread,
out int totalentries,
IntPtr resume_handle
);
[DllImport("Netapi32.dll", SetLastError=true)]
static extern int NetApiBufferFree(IntPtr Buffer);

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=4)]
struct FILE_INFO_3
{
public int fi3_id;
public int fi3_permission;
public int fi3_num_locks;
public string fi3_pathname;
public string fi3_username;
}

int dwStatus = NetFileEnum(servername, null, null, 3, ref pBuffer, -1,
out dwReadEntries, out dwTotalEntries, IntPtr.Zero );


int dwReadEntries;
int dwTotalEntries;
IntPtr pBuffer = IntPtr.Zero ;
FILE_INFO_3 pCurrent = new FILE_INFO_3();
if (dwStatus == 0)
{
for (int dwIndex=0; dwIndex < dwReadEntries; dwIndex++)
{
IntPtr iPtr = new IntPtr(pBuffer.ToInt32() + (dwIndex *
Marshal.SizeOf(pCurrent)));
pCurrent = (FILE_INFO_3) Marshal.PtrToStructure(iPtr,
typeof(FILE_INFO_3));
Console.WriteLine("dwIndex={0}", dwIndex);
Console.WriteLine(" id={0}", pCurrent.fi3_id );
Console.WriteLine(" pathname={0}", pCurrent.fi3_pathname);
Console.WriteLine(" username={0}", pCurrent.fi3_username);
}
NetApiBufferFree(pBuffer);
}


thanks
Phil
 
P

phancey

ok, it was because, although I had opened it, Visual Studio did not
keep it open but simply made a copy of it. When I opened the same file
in Word, it appeared!

Now, how do I close it using NetFileClose?
 
P

phancey

no, done that now but it doesn't really do the job.

For instance, if someone leaves a document open in Word overnight, I
want to automatically kick them off (release the locks) and then copy
over a new document to replace the old one. Although NetFileClose seems
to work (and indeed, on the next run of NetFileEnum, the file is no
longer seen as "open"), the lock in fact remains and the document
cannot be overwritten.

So how do I close the lock/connection completely?

TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top