如何使用C#开发一个类似于live skydrive中的文件上传器控件

发布于 2024-08-03 10:10:52 字数 49 浏览 3 评论 0原文

我喜欢拖拽skydrive 文件上传控件的 drop 功能。我该如何开发类似的控件?

I like the drag & drop feature of the skydrive file upload control. How do i go about developing a similar control?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

秋日私语 2024-08-10 10:10:52

检查我的源代码是否有用

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>

check my source code if it's useful

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>
屌丝范 2024-08-10 10:10:52

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

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

C# will only assist you at the sever side of this feature, most of it uses Java Script (client side) to upload the files in a pretty AJAX way (very similar to GMail attachments). You can use the following example to implement something similar to Skydrive's.

This can assist you of implementing the asynchronous upload part.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文