Solved

how to download a file a from web service in c#or vb.net 2005

Posted on 2007-11-20
4
639 Views
Last Modified: 2010-07-27
I want to create a web service which will check a database for the my application version and if it find any new verson then it will send a file (latest Setup) to the client computer. so that the client can have the latest update.

i want to ask that is it possible that my web serive send the the latest setup file to the client computer.
and if yes then how (some code sample).

and also i want to do this process silently, i means i donot want to show any screen or dialog untill the update is donwloaded on the client pc.
0
Comment
Question by:ziorrinfotech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 125 total points
ID: 20326002
In the web service you can return the data of the file:

[WebMethod]
public byte[] GetLatestSetup() {
   return System.IO.File.ReadAllBytes(setupFileName);
}

On the client you call the service:

using (service = new TheWebReference()) {
   byte[] data = service.GetLatestSetup();
}
System.IO.WriteAllBytes(localSetupFileName, data);

You might want to add a method to check the version of the settings, so that you don't have to download it every time.
0
 

Author Comment

by:ziorrinfotech
ID: 20332807
GreenGhost

the code which you suggested is working fine if i run this on my local machine and give
 setupFileName = localmachine path (E:\setup.exe)

but when i gave a path other other the local machine then it gives me the error mention below.
i want to download a file which exists on internet server
so i gave this value in setupFileName ="http://xxx.com/update/setup.exe"

then it gave me this error.
pls help me how can i solve this issue

System.Web.Services.Protocols.SoapException was unhandled by user code
  Message="System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentException: URI formats are not supported.\n   at System.IO.Path.NormalizePathFast(String path, Boolean fullCheck)\n   at System.IO.Path.GetFullPathInternal(String path)\n   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)\n   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)\n   at System.IO.File.ReadAllBytes(String path)\n   at ClipWebService.GetLatestSetup() in f:\\Deepak\\Personal\\Asp.net2.0\\Practise\\ClipWebService\\App_Code\\ClipWebService.cs:line 30\n   --- End of inner exception stack trace ---"
  Source="System.Web.Services"
  Actor=""
  Lang=""
  Node=""
  Role=""
  StackTrace:
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at localhost.ClipWebService.GetLatestSetup() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\clipwebsite\bfa64d05\baaed92c\App_WebReferences.pebyhuhu.0.cs:line 93
       at _Default.Button2_Click(Object sender, EventArgs e) in f:\Deepak\Personal\Asp.net2.0\Practise\ClipWebSite\Default.aspx.cs:line 29
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)



0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20333108
You can't use an URL to open a file. Either use an UNC path (like \\servername\path\to\file\thefile), or send a http request for the file (using the WebClient class for example).

Why don't you just put the web service on the server where the file is?
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20335816
Is there something missing in the solution, or why did you grade it B?

I see that you rarely give A grades, eventhough the solutions given to you seem perfectly fine. If you grade poorly, people will hesitate to help you.
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question