How to allow the user to download files from the server?


hi

i using sl4 , business application template. 

i have folder on server contains files (jpgs, word docs, excel docs etc) and directory store holds paths of these files.  this list displayed on 1 of silverlight webpages.  possible for user select file want , download it?  if so, what need achieve this? if not, approach need take? folder of files acquire new files regularly, may on daily basis, needs quite flexible.

any appreciated.

thanks

adam

make sure have located files in sub folder of web application. example: web application's location c:\myprojects\myapp, example place files in c:\myprojects\myapp\files.

then note url shown in browser application. http://localhost/myapp/mysite.aspx. can build path files combining information, e.g. http://localhost/myapp/files/ "root" folder of files repository.

to avoid run problems when move application server, there various methods dynamically retrieve path of current web application. starters, can leave out server part. if url http://localhost/myapp, use "/myapp" base url.

now let's go through step step:

  1. let's application local path c:\myprojects\myapp
  2. the base url of application /myapp
  3. you want download file has stored physical location of file:///c:/myprojects/myapp/files/docs/my.docx
  4. cut off path application root, /files/docs/my.docx
  5. combine application base url path, e.g. /myapp/files/docs/my.docx
  6. use string url link:

string uritext = "/myapp/files/docs/my.docx"  uri uri = new uri(uritext, urikind.relative);  htmlpage.window.navigate(uri, "_blank");


please note definition of uri has changed include urikind (relative) that.

other it's hard give proper advice. not elegant solution, explaining in more detail not possible in forum post. i'd recommend read of basics of web site hosting (e.g. virtual directories) , involved technologies better understanding of happens here.

good luck!




Silverlight  >  Programming Silverlight with .NET – General



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........