zoukankan      html  css  js  c++  java
  • ASP.NET makes uploading files from the client to the server a snap(UploadInterface.PostedFile.SaveAs)

    http://www.computerbooksonline.com/tips/asp11.asp
    In a previous tip, we talked about uploading files via classic ASP. As you saw, getting the file from the client to the server isn't a big deal, but getting ASP to handle the file properly, once delivered, was no walk in the park. Fortunately, like most other tasks that were once tedious or impossible in ASP, ASP.NET makes this task simple.

    All you have to do is provide the interface for the upload, in the same way you would do with ASP--the tag corresponds in ASP.NET to a server-side System.Web.UI.HtmlControls.HtmlInputFile control, which is rendered in HTML in exactly the same way. Then, in your code-behind page, use something like the following intuitive code:

    Protected Sub UploadButton_OnClick(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles UploadButton.Click
    Dim FileUpload As HttpPostedFile
    Dim UploadedFileName As String

    'Get the file from the HtmlInputFile control
    FileUpload = UploadInterface.PostedFile

    If Not UploadInterface.PostedFile Is Nothing Then
    'Get just the filename (without the client path)
    UploadedFileName =
    FileUpload.FileName.Substring(FileUpload.FileName.LastIndexOf("\"))
    'Save it in a safe place on the server
    UploadInterface.PostedFile.SaveAs("c:\temp\" & UploadedFileName)
    End If
    End Sub

  • 相关阅读:
    前后端反爬虫的一些奇怪姿势【转载】
    Scrapy 中常用的中间件和管道组件
    Jquery各个版本的区别
    userAgent
    操作系统
    手机类别
    移动端设备UA检测
    iPhone6的CSS3媒体查询
    所有设备的CSS像素
    解读所有设备的css像素的网站
  • 原文地址:https://www.cnblogs.com/cy163/p/280709.html
Copyright © 2011-2022 走看看