Solved

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

Posted on 2007-11-20
4
617 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
  • 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now