?
Solved

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

Posted on 2007-11-20
4
Medium Priority
?
647 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 375 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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