Assembly conversion to Pocket Pc format

H

Harsha

Hi,

I want to convert windows assemblies to Pocket PC format. Is it possible ?
If so how to do that ? Do we have any tools to convert as have tools for
converting video and audio files to Pocket PC format ?

Thanks in Advance

Harsha.
 
C

Christopher Fairbairn

Hi Harsha,

Harsha said:
I want to convert windows assemblies to Pocket PC format. Is it possible ?
If so how to do that ? Do we have any tools to convert as have tools for
converting video and audio files to Pocket PC format ?

I don't think you'll find any automated tools for doing this kind of thing.
In certain respects there is no difference in format (i.e. the PE file
format used by *.dll and *.exe is essentially the same between both
platforms), but in others the differences between the .NET CF and full
framework are too great for an automated tool to perform without user
intervention.

If you take an assembly compiled for the .NET Compact Framework it will run
on the desktop without modification, assuming you only use the subset of
functionality supported on both platforms. You will get TypeLoad and
MethodMissing exceptions at runtime if your code references anything which
is not present on the current platform.

The opposite is not true. You can not take an assembly compiled for the
desktop and run it on the .NET CF without modification. If you have a
desktop assembly you realistically need to recompile it in order to get it
working on the .NET Compact Framework. When recompiling you will notice via
errors which features are not present within the base class libraries and
need code modifications to work around. You will also have a manual process
altering the code to cope with the different UI conventions and platform
limitations etc.

Daniel Moth has a good series of blog posts discussing this topic. For
example http://www.danielmoth.com/Blog/2004/09/retargetable-256.html

Hope this helps,
Christopher Fairbairn
 
H

Harsha

Thank you very much Christopher for your time and response.

I am really sorry to say that I was not specific about my question.

My scenario is I have set of Compact framework DLL's (Not winodws assembly).
Till date I used to manually paste those into my device. While doing that it
used to copy and convert those assemblies into device format.

Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.

In brief my question is how to copy and convert an assembly into device
without using activesynch ?

FYI those assemblies are CF assemblies not windows assemblies.

Hope I am much clear now.

Thanks..

Harsha.
 
C

Christopher Fairbairn

Hi,

Harsha said:
My scenario is I have set of Compact framework DLL's (Not winodws
assembly).
Till date I used to manually paste those into my device. While doing that
it
used to copy and convert those assemblies into device format.

Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.
Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text
file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.

As long as the files are being treated as binary data and not text data by
any code related to the HTTP transfer the assemblies should transfer over
HTTP or HTTPS just fine without any modification or conversion required.

Hope this helps,
Christopher Fairbairn
 
H

Harsha

Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.
 
G

Guest

You're talking about the cryptic message from ActiveSync

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

when you drag and drop in Explorer on the desktop. It only applies to
things like Word and Excel files - no "conversion" is done for DLLs (even
though it says there is). Just copy them and you're fine.
 
S

Simon Hart [MVP]

On the client end you are using StreamReader and StreamWriter. These classes
are usally used for text files not binary plus you could have encoding
issues. Calling ReadLine and WriteLine will append \r\n carriage return and
line feed characters to each buffer read/write. This is probebly why it is
not working for you. Try using BinaryReader/BinaryWriter classes, and the
Read and Write methods.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.



Christopher Fairbairn said:
Hi,



Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.


As long as the files are being treated as binary data and not text data by
any code related to the HTTP transfer the assemblies should transfer over
HTTP or HTTPS just fine without any modification or conversion required.

Hope this helps,
Christopher Fairbairn
 
H

Harsha

Thank you very much Mr. Hart for your time and response.

In MSDN I found out an article which is close to this. That says how to
upload and download files in compact framework.

Link of that document is
http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I replicated the steps given ( please click on the above link ) and could
successfully download files to device. But I couldn't download any dll's. But
I can download text files,xml files,images.
I want to with this application can I download dll files ? If not what
changes I have to make do so ?

Thanks in advance.

Harsha.



Simon Hart said:
On the client end you are using StreamReader and StreamWriter. These classes
are usally used for text files not binary plus you could have encoding
issues. Calling ReadLine and WriteLine will append \r\n carriage return and
line feed characters to each buffer read/write. This is probebly why it is
not working for you. Try using BinaryReader/BinaryWriter classes, and the
Read and Write methods.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.



Christopher Fairbairn said:
Hi,

My scenario is I have set of Compact framework DLL's (Not winodws
assembly).
Till date I used to manually paste those into my device. While doing that
it
used to copy and convert those assemblies into device format.

Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.

Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text
file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.

As long as the files are being treated as binary data and not text data by
any code related to the HTTP transfer the assemblies should transfer over
HTTP or HTTPS just fine without any modification or conversion required.

Hope this helps,
Christopher Fairbairn
 
S

Simon Hart [MVP]

It should also work with binary files, show us the PDA code now you've
amended it.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thank you very much Mr. Hart for your time and response.

In MSDN I found out an article which is close to this. That says how to
upload and download files in compact framework.

Link of that document is
http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I replicated the steps given ( please click on the above link ) and could
successfully download files to device. But I couldn't download any dll's. But
I can download text files,xml files,images.
I want to with this application can I download dll files ? If not what
changes I have to make do so ?

Thanks in advance.

Harsha.



Simon Hart said:
On the client end you are using StreamReader and StreamWriter. These classes
are usally used for text files not binary plus you could have encoding
issues. Calling ReadLine and WriteLine will append \r\n carriage return and
line feed characters to each buffer read/write. This is probebly why it is
not working for you. Try using BinaryReader/BinaryWriter classes, and the
Read and Write methods.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.



:

Hi,

My scenario is I have set of Compact framework DLL's (Not winodws
assembly).
Till date I used to manually paste those into my device. While doing that
it
used to copy and convert those assemblies into device format.

Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.

Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text
file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.

As long as the files are being treated as binary data and not text data by
any code related to the HTTP transfer the assemblies should transfer over
HTTP or HTTPS just fine without any modification or conversion required.

Hope this helps,
Christopher Fairbairn
 
H

Harsha

Thank you Hart .

I am sending you the code I have used. Below is the function I have used to
download file to device. This is same as given in MSDN.

public void DownloadFileBinary(string localFile, string downloadUrl)
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];

// loop through response stream reading each data block
// and writing to the local file
int bytesRead = respStream.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
wrtr.Write(inData, 0, bytesRead);
bytesRead = respStream.Read(inData, 0, inData.Length);
}

respStream.Close();
wrtr.Close();
}

I am calling this function as given below.

DownloadFileBinary("abc.dll",
"http://16.138.51.50/DownloadCABForMypaq/abc.dll");


It is throwing exception at

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Error message is "An error message cannot be displayed because an optional
resource assembly containing it cannot be found"

And stack trace of the exception is

at System.Net.HttpWebRequest.finishGetResponse()
at System.Net.HttpWebRequest.GetResponse()
at UploadDownload.Form1.DownloadFileBinary()
at UploadDownload.Form1.btnDownloadbinary_Click()
at System.Windows.Forms.Control.OnClick()
at System.Windows.Forms.Button.OnClick()
at System.Windows.Forms.ButtonBase.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at UploadDownload.Program.Main()



Thank you very much for you Patience.

Harsha.


Simon Hart said:
It should also work with binary files, show us the PDA code now you've
amended it.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thank you very much Mr. Hart for your time and response.

In MSDN I found out an article which is close to this. That says how to
upload and download files in compact framework.

Link of that document is
http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I replicated the steps given ( please click on the above link ) and could
successfully download files to device. But I couldn't download any dll's. But
I can download text files,xml files,images.
I want to with this application can I download dll files ? If not what
changes I have to make do so ?

Thanks in advance.

Harsha.



Simon Hart said:
On the client end you are using StreamReader and StreamWriter. These classes
are usally used for text files not binary plus you could have encoding
issues. Calling ReadLine and WriteLine will append \r\n carriage return and
line feed characters to each buffer read/write. This is probebly why it is
not working for you. Try using BinaryReader/BinaryWriter classes, and the
Read and Write methods.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.



:

Hi,

My scenario is I have set of Compact framework DLL's (Not winodws
assembly).
Till date I used to manually paste those into my device. While doing that
it
used to copy and convert those assemblies into device format.

Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.

Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text
file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.

As long as the files are being treated as binary data and not text data by
any code related to the HTTP transfer the assemblies should transfer over
HTTP or HTTPS just fine without any modification or conversion required.

Hope this helps,
Christopher Fairbairn
 
S

Simon Hart [MVP]

That's probably because you are writing 4096 byte blocks. You're better off
declaring the size of the buffer for each write. So for example if your file
is 8,000 bytes, you need to subtract the 4096 from 8,000 and declare a buffer
in case of 3904 bytes. You're binary files currently will not have proper eof
markers. This is required for binary files not text files.

--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thank you Hart .

I am sending you the code I have used. Below is the function I have used to
download file to device. This is same as given in MSDN.

public void DownloadFileBinary(string localFile, string downloadUrl)
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];

// loop through response stream reading each data block
// and writing to the local file
int bytesRead = respStream.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
wrtr.Write(inData, 0, bytesRead);
bytesRead = respStream.Read(inData, 0, inData.Length);
}

respStream.Close();
wrtr.Close();
}

I am calling this function as given below.

DownloadFileBinary("abc.dll",
"http://16.138.51.50/DownloadCABForMypaq/abc.dll");


It is throwing exception at

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Error message is "An error message cannot be displayed because an optional
resource assembly containing it cannot be found"

And stack trace of the exception is

at System.Net.HttpWebRequest.finishGetResponse()
at System.Net.HttpWebRequest.GetResponse()
at UploadDownload.Form1.DownloadFileBinary()
at UploadDownload.Form1.btnDownloadbinary_Click()
at System.Windows.Forms.Control.OnClick()
at System.Windows.Forms.Button.OnClick()
at System.Windows.Forms.ButtonBase.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at UploadDownload.Program.Main()



Thank you very much for you Patience.

Harsha.


Simon Hart said:
It should also work with binary files, show us the PDA code now you've
amended it.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thank you very much Mr. Hart for your time and response.

In MSDN I found out an article which is close to this. That says how to
upload and download files in compact framework.

Link of that document is
http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I replicated the steps given ( please click on the above link ) and could
successfully download files to device. But I couldn't download any dll's. But
I can download text files,xml files,images.
I want to with this application can I download dll files ? If not what
changes I have to make do so ?

Thanks in advance.

Harsha.



:

On the client end you are using StreamReader and StreamWriter. These classes
are usally used for text files not binary plus you could have encoding
issues. Calling ReadLine and WriteLine will append \r\n carriage return and
line feed characters to each buffer read/write. This is probebly why it is
not working for you. Try using BinaryReader/BinaryWriter classes, and the
Read and Write methods.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.



:

Hi,

My scenario is I have set of Compact framework DLL's (Not winodws
assembly).
Till date I used to manually paste those into my device. While doing that
it
used to copy and convert those assemblies into device format.

Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.

Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text
file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.

As long as the files are being treated as binary data and not text data by
any code related to the HTTP transfer the assemblies should transfer over
HTTP or HTTPS just fine without any modification or conversion required.

Hope this helps,
Christopher Fairbairn
 
H

Harsha

Thank you very much Mr. Hart.

But in my case it is throwing exception before executing that statement what
you have mentioned. That is before reading buffer size it is throwing
exception. As I have mentioned in my previous post exception occurs at the
line

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

And the code is as below. That is it is throwing exception even before
allocating buffer size.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];


Still if you feel that buffer size is the cause for the issue then please
let me know how to know the size of the dll which will be on server and also
please explain how to code and apply that in my case ?

Thanks a lot.

Harsha.

Simon Hart said:
That's probably because you are writing 4096 byte blocks. You're better off
declaring the size of the buffer for each write. So for example if your file
is 8,000 bytes, you need to subtract the 4096 from 8,000 and declare a buffer
in case of 3904 bytes. You're binary files currently will not have proper eof
markers. This is required for binary files not text files.

--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thank you Hart .

I am sending you the code I have used. Below is the function I have used to
download file to device. This is same as given in MSDN.

public void DownloadFileBinary(string localFile, string downloadUrl)
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];

// loop through response stream reading each data block
// and writing to the local file
int bytesRead = respStream.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
wrtr.Write(inData, 0, bytesRead);
bytesRead = respStream.Read(inData, 0, inData.Length);
}

respStream.Close();
wrtr.Close();
}

I am calling this function as given below.

DownloadFileBinary("abc.dll",
"http://16.138.51.50/DownloadCABForMypaq/abc.dll");


It is throwing exception at

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Error message is "An error message cannot be displayed because an optional
resource assembly containing it cannot be found"

And stack trace of the exception is

at System.Net.HttpWebRequest.finishGetResponse()
at System.Net.HttpWebRequest.GetResponse()
at UploadDownload.Form1.DownloadFileBinary()
at UploadDownload.Form1.btnDownloadbinary_Click()
at System.Windows.Forms.Control.OnClick()
at System.Windows.Forms.Button.OnClick()
at System.Windows.Forms.ButtonBase.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at UploadDownload.Program.Main()



Thank you very much for you Patience.

Harsha.


Simon Hart said:
It should also work with binary files, show us the PDA code now you've
amended it.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thank you very much Mr. Hart for your time and response.

In MSDN I found out an article which is close to this. That says how to
upload and download files in compact framework.

Link of that document is
http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I replicated the steps given ( please click on the above link ) and could
successfully download files to device. But I couldn't download any dll's. But
I can download text files,xml files,images.
I want to with this application can I download dll files ? If not what
changes I have to make do so ?

Thanks in advance.

Harsha.



:

On the client end you are using StreamReader and StreamWriter. These classes
are usally used for text files not binary plus you could have encoding
issues. Calling ReadLine and WriteLine will append \r\n carriage return and
line feed characters to each buffer read/write. This is probebly why it is
not working for you. Try using BinaryReader/BinaryWriter classes, and the
Read and Write methods.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.



:

Hi,

My scenario is I have set of Compact framework DLL's (Not winodws
assembly).
Till date I used to manually paste those into my device. While doing that
it
used to copy and convert those assemblies into device format.

Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.

Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text
file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.

As long as the files are being treated as binary data and not text data by
any code related to the HTTP transfer the assemblies should transfer over
HTTP or HTTPS just fine without any modification or conversion required.

Hope this helps,
Christopher Fairbairn
 
S

Simon Hart [MVP]

Ah, of course. This exception could be for many reasons. Suggest you install
System_SR (<= Cf 2.0, otherwise NETCFv35.Messages) as this will give
detailed information on the exception, but from the error it looks like CF
2.0 or CF1.0.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thank you very much Mr. Hart.

But in my case it is throwing exception before executing that statement what
you have mentioned. That is before reading buffer size it is throwing
exception. As I have mentioned in my previous post exception occurs at the
line

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

And the code is as below. That is it is throwing exception even before
allocating buffer size.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];


Still if you feel that buffer size is the cause for the issue then please
let me know how to know the size of the dll which will be on server and also
please explain how to code and apply that in my case ?

Thanks a lot.

Harsha.

Simon Hart said:
That's probably because you are writing 4096 byte blocks. You're better off
declaring the size of the buffer for each write. So for example if your file
is 8,000 bytes, you need to subtract the 4096 from 8,000 and declare a buffer
in case of 3904 bytes. You're binary files currently will not have proper eof
markers. This is required for binary files not text files.

--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thank you Hart .

I am sending you the code I have used. Below is the function I have used to
download file to device. This is same as given in MSDN.

public void DownloadFileBinary(string localFile, string downloadUrl)
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];

// loop through response stream reading each data block
// and writing to the local file
int bytesRead = respStream.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
wrtr.Write(inData, 0, bytesRead);
bytesRead = respStream.Read(inData, 0, inData.Length);
}

respStream.Close();
wrtr.Close();
}

I am calling this function as given below.

DownloadFileBinary("abc.dll",
"http://16.138.51.50/DownloadCABForMypaq/abc.dll");


It is throwing exception at

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Error message is "An error message cannot be displayed because an optional
resource assembly containing it cannot be found"

And stack trace of the exception is

at System.Net.HttpWebRequest.finishGetResponse()
at System.Net.HttpWebRequest.GetResponse()
at UploadDownload.Form1.DownloadFileBinary()
at UploadDownload.Form1.btnDownloadbinary_Click()
at System.Windows.Forms.Control.OnClick()
at System.Windows.Forms.Button.OnClick()
at System.Windows.Forms.ButtonBase.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at UploadDownload.Program.Main()



Thank you very much for you Patience.

Harsha.


:

It should also work with binary files, show us the PDA code now you've
amended it.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thank you very much Mr. Hart for your time and response.

In MSDN I found out an article which is close to this. That says how to
upload and download files in compact framework.

Link of that document is
http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I replicated the steps given ( please click on the above link ) and could
successfully download files to device. But I couldn't download any dll's. But
I can download text files,xml files,images.
I want to with this application can I download dll files ? If not what
changes I have to make do so ?

Thanks in advance.

Harsha.



:

On the client end you are using StreamReader and StreamWriter. These classes
are usally used for text files not binary plus you could have encoding
issues. Calling ReadLine and WriteLine will append \r\n carriage return and
line feed characters to each buffer read/write. This is probebly why it is
not working for you. Try using BinaryReader/BinaryWriter classes, and the
Read and Write methods.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.



:

Hi,

My scenario is I have set of Compact framework DLL's (Not winodws
assembly).
Till date I used to manually paste those into my device. While doing that
it
used to copy and convert those assemblies into device format.

Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.

Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text
file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.

As long as the files are being treated as binary data and not text data by
any code related to the HTTP transfer the assemblies should transfer over
HTTP or HTTPS just fine without any modification or conversion required.

Hope this helps,
Christopher Fairbairn
 
H

Harsha

Thank you very much Hart.

I installed System_SR on my device. Still it is not showing any detail
information about the exception. except the error message "An error message
cannot be displayed because an optional resource assembly containing it
cannot be found".

So please guide me how to fix this issue. That what I need to do to download
dll files. I could download all other type of files as given in the below
msdn page.

http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I installed System_SR. Any help is appreciated .


Regards,

Harsha.


Simon Hart said:
Ah, of course. This exception could be for many reasons. Suggest you install
System_SR (<= Cf 2.0, otherwise NETCFv35.Messages) as this will give
detailed information on the exception, but from the error it looks like CF
2.0 or CF1.0.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thank you very much Mr. Hart.

But in my case it is throwing exception before executing that statement what
you have mentioned. That is before reading buffer size it is throwing
exception. As I have mentioned in my previous post exception occurs at the
line

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

And the code is as below. That is it is throwing exception even before
allocating buffer size.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];


Still if you feel that buffer size is the cause for the issue then please
let me know how to know the size of the dll which will be on server and also
please explain how to code and apply that in my case ?

Thanks a lot.

Harsha.

Simon Hart said:
That's probably because you are writing 4096 byte blocks. You're better off
declaring the size of the buffer for each write. So for example if your file
is 8,000 bytes, you need to subtract the 4096 from 8,000 and declare a buffer
in case of 3904 bytes. You're binary files currently will not have proper eof
markers. This is required for binary files not text files.

--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thank you Hart .

I am sending you the code I have used. Below is the function I have used to
download file to device. This is same as given in MSDN.

public void DownloadFileBinary(string localFile, string downloadUrl)
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];

// loop through response stream reading each data block
// and writing to the local file
int bytesRead = respStream.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
wrtr.Write(inData, 0, bytesRead);
bytesRead = respStream.Read(inData, 0, inData.Length);
}

respStream.Close();
wrtr.Close();
}

I am calling this function as given below.

DownloadFileBinary("abc.dll",
"http://16.138.51.50/DownloadCABForMypaq/abc.dll");


It is throwing exception at

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Error message is "An error message cannot be displayed because an optional
resource assembly containing it cannot be found"

And stack trace of the exception is

at System.Net.HttpWebRequest.finishGetResponse()
at System.Net.HttpWebRequest.GetResponse()
at UploadDownload.Form1.DownloadFileBinary()
at UploadDownload.Form1.btnDownloadbinary_Click()
at System.Windows.Forms.Control.OnClick()
at System.Windows.Forms.Button.OnClick()
at System.Windows.Forms.ButtonBase.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at UploadDownload.Program.Main()



Thank you very much for you Patience.

Harsha.


:

It should also work with binary files, show us the PDA code now you've
amended it.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thank you very much Mr. Hart for your time and response.

In MSDN I found out an article which is close to this. That says how to
upload and download files in compact framework.

Link of that document is
http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I replicated the steps given ( please click on the above link ) and could
successfully download files to device. But I couldn't download any dll's. But
I can download text files,xml files,images.
I want to with this application can I download dll files ? If not what
changes I have to make do so ?

Thanks in advance.

Harsha.



:

On the client end you are using StreamReader and StreamWriter. These classes
are usally used for text files not binary plus you could have encoding
issues. Calling ReadLine and WriteLine will append \r\n carriage return and
line feed characters to each buffer read/write. This is probebly why it is
not working for you. Try using BinaryReader/BinaryWriter classes, and the
Read and Write methods.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.



:

Hi,

My scenario is I have set of Compact framework DLL's (Not winodws
assembly).
Till date I used to manually paste those into my device. While doing that
it
used to copy and convert those assemblies into device format.

Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.

Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text
file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.

As long as the files are being treated as binary data and not text data by
any code related to the HTTP transfer the assemblies should transfer over
HTTP or HTTPS just fine without any modification or conversion required.

Hope this helps,
Christopher Fairbairn
 
H

Harsha

Hi,

This is to let you know that I fixed my issue. The solution I found out was
to change the ext from dll to txt. As you know I was facing problem to
download dll and exe's. The statement was as below.

DownloadFileBinary("abc.dll",
"http://xx.xxx.xx.xx/DownloadCABForMypaq/abc.dll");

I changed that to DownloadFileBinary("abc.dll",
"http://xx.xxx.xx.xx/DownloadCABForMypaq/abc.dll.txt");

I added txt to file name..so my issue got fixed..

But thank you very much for your guidence.

Harsha





Harsha said:
Thank you very much Hart.

I installed System_SR on my device. Still it is not showing any detail
information about the exception. except the error message "An error message
cannot be displayed because an optional resource assembly containing it
cannot be found".

So please guide me how to fix this issue. That what I need to do to download
dll files. I could download all other type of files as given in the below
msdn page.

http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I installed System_SR. Any help is appreciated .


Regards,

Harsha.


Simon Hart said:
Ah, of course. This exception could be for many reasons. Suggest you install
System_SR (<= Cf 2.0, otherwise NETCFv35.Messages) as this will give
detailed information on the exception, but from the error it looks like CF
2.0 or CF1.0.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


Harsha said:
Thank you very much Mr. Hart.

But in my case it is throwing exception before executing that statement what
you have mentioned. That is before reading buffer size it is throwing
exception. As I have mentioned in my previous post exception occurs at the
line

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

And the code is as below. That is it is throwing exception even before
allocating buffer size.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];


Still if you feel that buffer size is the cause for the issue then please
let me know how to know the size of the dll which will be on server and also
please explain how to code and apply that in my case ?

Thanks a lot.

Harsha.

:

That's probably because you are writing 4096 byte blocks. You're better off
declaring the size of the buffer for each write. So for example if your file
is 8,000 bytes, you need to subtract the 4096 from 8,000 and declare a buffer
in case of 3904 bytes. You're binary files currently will not have proper eof
markers. This is required for binary files not text files.

--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thank you Hart .

I am sending you the code I have used. Below is the function I have used to
download file to device. This is same as given in MSDN.

public void DownloadFileBinary(string localFile, string downloadUrl)
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

// Retrieve response stream
Stream respStream = resp.GetResponseStream();

// Create local file
FileStream wrtr = new FileStream(localFile, FileMode.Create);

// Allocate byte buffer to hold stream contents
byte[] inData = new byte[4096];

// loop through response stream reading each data block
// and writing to the local file
int bytesRead = respStream.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
wrtr.Write(inData, 0, bytesRead);
bytesRead = respStream.Read(inData, 0, inData.Length);
}

respStream.Close();
wrtr.Close();
}

I am calling this function as given below.

DownloadFileBinary("abc.dll",
"http://16.138.51.50/DownloadCABForMypaq/abc.dll");


It is throwing exception at

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Error message is "An error message cannot be displayed because an optional
resource assembly containing it cannot be found"

And stack trace of the exception is

at System.Net.HttpWebRequest.finishGetResponse()
at System.Net.HttpWebRequest.GetResponse()
at UploadDownload.Form1.DownloadFileBinary()
at UploadDownload.Form1.btnDownloadbinary_Click()
at System.Windows.Forms.Control.OnClick()
at System.Windows.Forms.Button.OnClick()
at System.Windows.Forms.ButtonBase.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at UploadDownload.Program.Main()



Thank you very much for you Patience.

Harsha.


:

It should also work with binary files, show us the PDA code now you've
amended it.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thank you very much Mr. Hart for your time and response.

In MSDN I found out an article which is close to this. That says how to
upload and download files in compact framework.

Link of that document is
http://msdn2.microsoft.com/en-us/library/aa446517.aspx

I replicated the steps given ( please click on the above link ) and could
successfully download files to device. But I couldn't download any dll's. But
I can download text files,xml files,images.
I want to with this application can I download dll files ? If not what
changes I have to make do so ?

Thanks in advance.

Harsha.



:

On the client end you are using StreamReader and StreamWriter. These classes
are usally used for text files not binary plus you could have encoding
issues. Calling ReadLine and WriteLine will append \r\n carriage return and
line feed characters to each buffer read/write. This is probebly why it is
not working for you. Try using BinaryReader/BinaryWriter classes, and the
Read and Write methods.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Thanks for below information. I tried a sample code. I am sharing same with
you.

sample code -> web application runnin on IIS


{
string strfilename =
"c:\\inetpub\\wwwroot\\DownloadCABForMypaq\\mypaq\\mypaq.exe";
System.IO.BinaryReader BR = new
System.IO.BinaryReader(File.Open(strfilename , FileMode.Open,
FileAccess.Read));
BR.BaseStream.Position = 0;
byte[] binFile = BR.ReadBytes(Convert.ToInt32(BR.BaseStream.Length));
Response.BinaryWrite(binFile);

BR.Close();
Response.End();
Response.Flush();
}


Client application - running in PDA (windows mobile 4x)

{
string FileName = "mypaq.exe";
string downloadUrl =
"http://16.138.51.97/DownloadCABForMypaq/DownloadCAB.aspx?file=" + FileName;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(downloadUrl);
req.Method = "GET";

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);
localFile = strAppExecPath1 + FileName;

// Create the local file
StreamWriter wrtr = new StreamWriter(localFile);

// loop through response stream reading each line
// and writing to the local file
string inLine = rdr.ReadLine();
int iSize = 0;
while (inLine != null)
{
wrtr.WriteLine(inLine);
iSize = iSize + inLine.Length;
inLine = rdr.ReadLine();
}

rdr.Close();
wrtr.Close();
}

Problem -> after download of the data from server it is stored in a file in
PDA.
when i try to run, the application does not run on PDA
the mypaq.exe is a device application compiled in .NET
can you check if i have done any mistake in coding.


Thanks for your patience.

Harsha.



:

Hi,

My scenario is I have set of Compact framework DLL's (Not winodws
assembly).
Till date I used to manually paste those into my device. While doing that
it
used to copy and convert those assemblies into device format.

Are you talking about the dialog that appears while transfering files to an
ActiveSync connected via Windows Explorer?

If so the conversion process mentioned in the dialog isn't doing anything
for .NET assemblies, i.e. it is simply passing them through unmodified.

Only files of certain file types are passed through a convertor when
transfered via ActiveSync and to my knowledge .NET assemblies are not one of
those file types. It's mainly wordprocessor and spreadsheet type formats
that are converted by ActiveSync for use with Pocket Word or Excel.

Now I want to automate that process and I don't want to manually copy them
rather I want to download from HTTP or HTTPS. So while downloading text
file
downloads properly. But for assembly's,images,videos format needs to be
changed as it was happening when we manually copy to device.
 

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