Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Closing all open child forms. 4 38
Copy/Clone an object. 9 29
vb.net - How to check if current user is an administrator? 6 34
Angular JS Route 3 50
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 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

22 Experts available now in Live!

Get 1:1 Help Now