问题描述
这是设计代码:
This is the design Code :
<%@ Import Namespace=" Purple.WebDesk.Models" %>
<%@ Page Title="" Language="C#" MasterPageFile="~/Shared/Site.Master" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="Purple.WebDesk.test" %>
<%@ Register Assembly="DevExpress.Web.v14.2, Version=14.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>
<%@ Register Src="~/Shared/UploadedFilesContainer.ascx" TagPrefix="dx" TagName="UploadedFilesContainer" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.uploadContainer
{
float: left;
margin-right: 80px;
}
.contentFooter
{
clear: both;
padding-top: 20px;
}
</style>
<script type="text/javascript">
function onFileUploadComplete(s, e) {
if (e.callbackData) {
var fileData = e.callbackData.split('|');
var fileName = fileData[0],
fileUrl = fileData[1],
fileSize = fileData[2];
FileContainer.AddFile(fileName, fileUrl, fileSize);
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="uploadContainer">
<dx:ASPxUploadControl ID="UploadControl" runat="server" ClientInstanceName="UploadControl" Width="320"
NullText="Select multiple files..." UploadMode="Advanced" ShowUploadButton="True" ShowProgressPanel="True"
>
<AdvancedModeSettings EnableMultiSelect="True" EnableFileList="True" EnableDragAndDrop="True" />
<ValidationSettings MaxFileSize="4194304" AllowedFileExtensions=".jpg,.jpeg,.gif,.png">
</ValidationSettings>
<ClientSideEvents FileUploadStart="function(s, e) { FileContainer.Clear(); }"
FileUploadComplete="onFileUploadComplete" />
</dx:ASPxUploadControl>
<br /><br />
<p class="note">
<dx:ASPxLabel ID="AllowedFileExtensionsLabel" runat="server" Text="Allowed file extensions: .jpg, .jpeg, .gif, .png." Font-Size="8pt">
</dx:ASPxLabel>
<br />
<dx:ASPxLabel ID="MaxFileSizeLabel" runat="server" Text="Maximum file size: 4 MB." Font-Size="8pt">
</dx:ASPxLabel>
</p>
</div>
<div>
<dx:UploadedFilesContainer ID="FileContainer" runat="server" Width="380" Height="180"
NameColumnWidth="240" SizeColumnWidth="70" HeaderText="Uploaded files" />
</div>
<div class="contentFooter">
<p class="Note">
Note: All files uploaded will be automatically deleted in 5 minutes.
</p>
</div>
</asp:Content>
这是cs代码:
this is the cs code :
const string UploadDirectory = @"D:\Projects\MojKw\Production\Purple\Trunk\Code\Purple.WebDesk\Shared";
protected void ASPxUploadControl1_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
{
string resultExtension = Path.GetExtension(e.UploadedFile.FileName);
string resultFileName = Path.ChangeExtension(Path.GetRandomFileName(), resultExtension);
string resultFileUrl = UploadDirectory + resultFileName;
string resultFilePath = MapPath(resultFileUrl);
e.UploadedFile.SaveAs(resultFilePath);
UploadingUtils.RemoveFileWithDelay(resultFileName, resultFilePath, 5);
string name = e.UploadedFile.FileName;
string url = ResolveClientUrl(resultFileUrl);
long sizeInKilobytes = e.UploadedFile.ContentLength / 1024;
string sizeText = sizeInKilobytes.ToString() + " KB";
e.CallbackData = name + "|" + url + "|" + sizeText;
}
当我点击上传按钮时文件无法上传原因?
我是什么错过了这段代码
when i click on upload button the file not upload why ?
what i missed in this code
推荐答案
<dx:aspxuploadcontrol id="ASPxUploadControl1" runat="server" xmlns:dx="#unknown">
OnFileUploadComplete="ASPxUploadControl1_FileUploadComplete"
FileUploadMode="OnPageLoad">
<clientsideevents fileuploadcomplete="function(s, e) {<br mode=" hold=" /> window.open(e.callbackData);<br mode=" /></dx:aspxuploadcontrol>
protected void ASPxUploadControl1_FileUploadComplete(object sender,FileUploadCompleteEventArgs e)
{
if (e.IsValid)
{
fileinfo = new System.IO.FileInfo(e.UploadedFile.FileName);
resfilename = MapPath(System.Web.Configuration.WebConfigurationManager.AppSettings [DocumentPath]。ToString())+\\ \\\+ fileinfo.Name;
e.UploadedFile.SaveAs(resfilename);
//Response.ContentType =Application / pdf;
//Response.TransmitFile(resfilename);
//Response.End();
}
}
protected void ASPxUploadControl1_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
{
if (e.IsValid)
{
fileinfo = new System.IO.FileInfo(e.UploadedFile.FileName);
resfilename = MapPath(System.Web.Configuration.WebConfigurationManager.AppSettings["DocumentPath"].ToString()) + "\\" + fileinfo.Name;
e.UploadedFile.SaveAs(resfilename);
//Response.ContentType = "Application/pdf";
//Response.TransmitFile(resfilename);
//Response.End();
}
}
这篇关于使用Aspxuploadcontrol控件时文件未上载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!