SilverLight下载任意文件技巧
xaml采用LinkButton 其NavigateUri属性链接到服务端下载的ashx文档 如 HyperlinkButton Margin="32,135,198,140" Content="HyperlinkButton" NavigateUri="http://localhost:1399/download.ashx" / download.ashx 如下 Code 1 Imports System.Web 2 Imports
xaml采用LinkButton 其NavigateUri属性链接到服务端下载的ashx文档
如
download.ashx如下
Code
1Imports System.Web
2Imports System.Web.Services
3Imports System.Net
4Public Class downloadClass download
5 Implements System.Web.IHttpHandler
6
7 Private ChunkSize As Long = 102400 '100K 每次读取文件,只读取100K,这样可以缓解服务器的压力
8
9 Sub ProcessRequest()Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
10 Dim fileName As String = "aaa.JPG" '客户端保存的文件名
11 Dim filePath As String = context.Server.MapPath("image/IMG_1370.JPG") '路径
12
13 Dim fileInfo As System.IO.FileInfo = New System.IO.FileInfo(filePath)
14
15 If fileInfo.Exists = True Then
16
17 Dim buffer(ChunkSize) As Byte
18
19 context.Response.Clear()
20 Dim iStream As System.IO.FileStream = System.IO.File.OpenRead(filePath)
21 Dim dataLengthToRead As Long = iStream.Length '获取下载的文件总大小
22
23 context.Response.ContentType = "application/octet-stream"
24 '通知浏览器下载文件而不是打开
25 context.Response.AddHeader("Content-Disposition", "attachment; filename=" & _
26 HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8))
27Loop1:
28 While dataLengthToRead > 0 And context.Response.IsClientConnected
29 Dim lengthRead As Integer = iStream.Read(buffer, 0, Convert.ToInt32(ChunkSize)) '读取的大小
30 context.Response.OutputStream.Write(buffer, 0, lengthRead)
31 context.Response.Flush()
32 dataLengthToRead = dataLengthToRead - lengthRead
33 End While
34
35 context.Response.Close()
36 context.Response.End()
37 End If
38
39 'context.Response.ContentType = "text/plain"
40 'context.Response.Write("Hello World!")
41
42 End Sub
43
44 ReadOnly Property IsReusable()Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
45 Get
46 Return False
47 End Get
48 End Property
49
50End Class

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

The superpeople game can be downloaded through the steam client. The size of this game is about 28G. It usually takes one and a half hours to download and install. Here is a specific download and installation tutorial for you! New method to apply for global closed testing 1) Search for "SUPERPEOPLE" in the Steam store (steam client download) 2) Click "Request access to SUPERPEOPLE closed testing" at the bottom of the "SUPERPEOPLE" store page 3) After clicking the request access button, The "SUPERPEOPLECBT" game can be confirmed in the Steam library 4) Click the install button in "SUPERPEOPLECBT" and download

As a convenient and practical network disk tool, Quark can help users easily obtain their favorite resources. What if you want to download a file locally? Let the editor tell you now, let’s learn it together! How to download Quark Network Disk to local sharing method 1. First open the Quark software, enter the homepage, and click the [Cloud Icon] on the lower right; 2. Then on the Quark Network Disk page, we click the [Document] function; 3. Then go to the document page, select the file you want to download, and click the [three-dot icon]; 4. After the final click, we click [Download] in the pop-up dialog box;

How to download and save Douyin videos? You can download and save videos in Douyin short video APP. Most users don’t know how to download and save Douyin videos. Next is the diagram of how to download and save Douyin videos brought by the editor. Text tutorial, interested users come and take a look! Tutorial on how to use Douyin: How to download and save Douyin videos 1. First open the Douyin short video APP, enter the main page and click the [Share] button on the right; 2. After that, the multi-function bar will expand below, slide to the right to find [ Save local] icon; 3. Then you need to wait for the download, and then the [Saved, please go to the album to view] border will appear; 4. Finally jump to the album page, and you can see that the video you just downloaded has been saved.

1. First we open file management. 2. Click Internal Storage. 3. Scroll down and sort to find Tencent (Tencent folder) starting with t. 4. Click to enter and find QQfile_recv, click to enter to view.

UC Browser is a browser that everyone is using. It allows everyone to get some unique online experience. It is super convenient and can search for a variety of resources for you, some of which you cannot enjoy on other platforms. Everyone can view his video works here. The content is very exciting. Everyone is immersed in it and can't stop at all. They also want to download the video locally so that they can watch it at any time. Whenever you want to watch it, you can just When I watched it, it was very convenient. I have sorted out the specific method of downloading the video. I hope it can help you. How to download videos to the local area in UC Browser: 1. Open UC Browser, click on the menu bar, and select Download/Video; 2. Click on the cached video; 3. Click on the video selection

Win11 Tips Sharing: One trick to skip Microsoft account login Windows 11 is the latest operating system launched by Microsoft, with a new design style and many practical functions. However, for some users, having to log in to their Microsoft account every time they boot up the system can be a bit annoying. If you are one of them, you might as well try the following tips, which will allow you to skip logging in with a Microsoft account and enter the desktop interface directly. First, we need to create a local account in the system to log in instead of a Microsoft account. The advantage of doing this is

As an indispensable accompaniment to children's growth, Beilehu's children's songs have won the love of countless parents and children with their cheerful melody, vivid pictures and entertaining and educational content. In order to allow babies to enjoy the joy brought by children's songs anytime and anywhere, many parents hope to download Beilehu's children's songs to their mobile phones or tablets so that they can listen to their children at any time, but how to save Beilehu's children's songs? On your mobile phone, this tutorial will bring you a detailed introduction. Users who don’t understand it yet can come and read along with this article to learn more. Beilehu Nursery Rhymes Download Children's Songs Multi-Picture Tutorial: Open the software and select a children's song you want to download. The editor takes "Classic Children's Songs" as an example. 2. Click the "Download" button below the children's song star.
