0

我喜欢 skydrive 文件上传控件的拖放功能。我如何着手开发类似的控件?

4

3 回答 3

0

检查我的源代码是否有用

using System;
using System.Data.ProviderBase;
using System.Text;
using System.Xml.Schema;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Globalization;
using System.Diagnostics;
using System.ComponentModel.Design;
using System.Data.Common;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void upload_Click(object sender, EventArgs e)
    {
if (fileupload.HasFile)
try {

    fileupload.SaveAs("C:\\Uploads\\" + fileupload.FileName);
lbl.Text = "File name: " +
fileupload.PostedFile.FileName + "<br>" +
fileupload.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
fileupload.PostedFile.ContentType;  
}
catch (Exception ex) {
lbl.Text = "ERROR: " + ex.Message.ToString(); 
}
else
{
lbl.Text = "You have not specified a file.";
} 
    }
}

HTML:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fileupload.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
<form id="myForm" runat="server">

<asp:FileUpload ID="fileupload" runat="server" />

<asp:Button ID="upload" Text="Upload" runat="server" onclick="upload_Click" />

<asp:Label ID="lbl" runat="server"></asp:Label>
</form>
</body>
</html>
于 2009-09-13T11:19:54.730 回答
0

C# 只会在此功能的服务器端为您提供帮助,其中大部分使用 Java 脚本(客户端)以漂亮的 AJAX 方式上传文件(非常类似于 GMail 附件)。您可以使用以下示例来实现类似于 Skydrive 的内容。

可以帮助您实现异步上传部分。

于 2009-09-02T21:09:06.430 回答
0

这是我找到的 SilverLight 解决方案:

http://www.silverlightshow.net/items/SL4-Desktop-Drag-and-Drop-Silver-Sky.aspx

于 2012-04-14T15:43:20.563 回答