Dossier partage

Résolu
titi035 Messages postés 173 Date d'inscription vendredi 13 janvier 2006 Statut Membre Dernière intervention 10 mai 2010 - 23 mars 2006 à 16:44
titi035 Messages postés 173 Date d'inscription vendredi 13 janvier 2006 Statut Membre Dernière intervention 10 mai 2010 - 24 mars 2006 à 17:58
Salut,

Est-ce qu'il y a une solution simple pour créer un répertoire partagé en Csharp?

Pour le moment, je fais ceci, et mon dossier est bien créé, mais je ne trouve d'options pour le metre en partage..


string sDirectory =
"C:\\Test";





if (!
Directory.Exists(sDirectory ))
{

Directory.CreateDirectory(sDirectory );

}

Titi035.

4 réponses

TheSaib Messages postés 2367 Date d'inscription mardi 17 avril 2001 Statut Membre Dernière intervention 26 décembre 2007 23
23 mars 2006 à 23:51
[DllImport("Netapi32.dll")]



private
static

extern

uint
NetShareAdd(


[MarshalAs(UnmanagedType.LPWStr)]
string strServer,


Int32 dwLevel,



ref SHARE_INFO_502 buf,



out
uint
parm_err


);


[DllImport("netapi32.dll", SetLastError=
true)]



static
extern

uint
NetShareDel(


[MarshalAs(UnmanagedType.LPWStr)]
string strServer,


[MarshalAs(UnmanagedType.LPWStr)]
string strNetName,


Int32 reserved
//must be 0


);


[DllImport("Netapi32.dll", CharSet=CharSet.Unicode)]



private
static

extern

int
NetShareEnum(


StringBuilder ServerName,



int level,



ref IntPtr bufPtr,



uint prefmaxlen,



ref
int
entriesread,



ref
int
totalentries,



ref
int
resume_handle


);


[DllImport("Netapi32.dll", SetLastError=
true)]



static
extern

int
NetApiBufferFree(IntPtr Buffer);



private
enum
NetError :
uint


{


NERR_Success = 0,


NERR_BASE = 2100,


NERR_UnknownDevDir = (NERR_BASE + 16),


NERR_DuplicateShare = (NERR_BASE + 18),


NERR_BufTooSmall = (NERR_BASE + 23),


}



private
enum
SHARE_TYPE :
uint


{


STYPE_DISKTREE = 0,


STYPE_PRINTQ = 1,


STYPE_DEVICE = 2,


STYPE_IPC = 3,


STYPE_SPECIAL = 0x80000000,


}


[StructLayout(LayoutKind.Sequential)]



private
struct
SHARE_INFO_502


{


[MarshalAs(UnmanagedType.LPWStr)]
public
string
shi502_netname;



public SHARE_TYPE shi502_type;


[MarshalAs(UnmanagedType.LPWStr)]
public
string
shi502_remark;



public Int32 shi502_permissions;



public Int32 shi502_max_uses;



public Int32 shi502_current_uses;


[MarshalAs(UnmanagedType.LPWStr)]
public
string
shi502_path;


[MarshalAs(UnmanagedType.LPWStr)]
public
string
shi502_passwd;



public Int32 shi502_reserved;



public IntPtr shi502_security_descriptor;


}



public static

bool
ShareFolder(
string
path,
string
name,
string
description)


{


SHARE_INFO_502 info =
new SHARE_INFO_502();


info.shi502_netname = name;
//nom de partage


info.shi502_type = SHARE_TYPE.STYPE_DISKTREE;
//Disque dur


info.shi502_remark = description;
//description du partage


info.shi502_permissions = 0;
//pas de permissions spécifiques


info.shi502_max_uses = -1;
//utilisateurs illimités


info.shi502_current_uses = 0;


info.shi502_path = path;
//chemin du partage


info.shi502_passwd =
null;
//Pas de pwd


info.shi502_reserved = 0;
//reserved sys


info.shi502_security_descriptor = IntPtr.Zero;



uint error = 0;



uint result = NetShareAdd(System.Net.Dns.GetHostName(), 502,
ref
info,
out
error);





if (result == (
uint
)NetError.NERR_Success)



return
true
;



return
false
;




}

::|The S@ib|::
MVP C#.NET
3
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
23 mars 2006 à 23:52
Salut,

Simple je ne pense pas, à mon avis tu vas devoir passer par la méthode NetShareAdd de l'API Win32.

/*
coq
MVP Visual C#
*/
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
23 mars 2006 à 23:53
Ca, c'est fait...

/*
coq
MVP Visual C#
*/
0
titi035 Messages postés 173 Date d'inscription vendredi 13 janvier 2006 Statut Membre Dernière intervention 10 mai 2010
24 mars 2006 à 17:58
Salut,

Merci les gars.. c'est pas très simple tout ça...

Titi035
0
Rejoignez-nous