Hi,
Yes, of course, you have to use RAPI.
Here is the code to copy a file
public static void CopyFileToPDA(s tring localfile, string remotefile)
{
//First Copy the executable
int fileh= RAPI.CeCreateFi le(remotefile, RAPI.GENERIC_WR ITE, 0, 0,
RAPI.CREATE_ALW AYS, RAPI.FILE_ATTRI BUTE_NORMAL, 0);
if ( fileh == 0)
throw new Exception("Erro r Creating Remote File : " );
FileStream reader = new FileStream(loca lfile,FileMode. Open);
byte[] buff = new Byte[ 400096];
int readed = 0;
int written=0;
while( (readed=reader. Read( buff, 0, 400096))>0)
RAPI.CeWriteFil e( fileh, buff, readed, out written, 0);
RAPI.CeCloseHan dle( fileh);
reader.Close();
}
public static void RapiInit()
{
try
{
if ( !isRAPIOpen)
CeRapiInit ();
isRAPIOpen = true;
}
catch(Exception e)
{
isRAPIOpen = false;
}
}
public static void RapiUninit ()
{
if ( isRAPIOpen )
CeRapiUninit();
isRAPIOpen = false;
}
These are the p/invoke that you need.
[DllImport("rapi .dll", CharSet=CharSet .Unicode)]
public static extern int CeDeleteFile(st ring remotefile);
[DllImport("rapi .dll", CharSet=CharSet .Unicode)]
public static extern int CeCloseHandle(i nt hObject);
[DllImport("rapi .dll", CharSet=CharSet .Unicode)]
public static extern int CeCreateFile(st ring lpFileName,uint
dwDesiredAccess ,int dwShareMode,int lpSecurityAttri butes,int
dwCreationDispo sition,int dwFlagsAndAttri butes,int hTemplateFile);
[DllImport("rapi .dll", CharSet=CharSet .Unicode)]
public static extern int CeRapiInitEx ([MarshalAs(Unman agedType.Struct )]
ref RAPIINIT pRapiInit);
[DllImport("rapi .dll", CharSet=CharSet .Unicode)]
protected static extern int CeRapiInit ();
[DllImport("rapi .dll", CharSet=CharSet .Unicode)]
protected static extern int CeRapiUninit ();
[DllImport("rapi .dll", CharSet=CharSet .Unicode)]
public static extern int CeReadFile(int hFile,byte[] lpBuffer,int
nNumberOfbytesT oRead, out int lpNumberOfbytes Read, int lpOverlapped);
[DllImport("rapi .dll", CharSet=CharSet .Unicode)]
public static extern int CeWriteFile(int hFile,byte[] buffer, int
nNumberOfbytesT oWrite, out int lpNumberOfbytes Written, int lpOverlapped);
[DllImport("rapi .dll", CharSet=CharSet .Unicode)]
public static extern int CeGetLastError( );
<Da***********@ gmail.comwrote in message
news:11******** **************@ x40g2000prg.goo glegroups.com.. .
Hi-
I'm trying to transfer files directly to a PDA via a Csharp program
I'm writing. Does anyone know how to do this (I obviously can't use
active sync).
Ohh yes, I'm running Vista.
-Thanks
-Dan