我已经使用ASP.NET开发了Web管理文档。 我对如何根据“用户个人资料”制作特定的文件夹感到困惑。因此,该架构就像用户上载文档时一样,它会根据其个人资料自动创建一个文件夹(例如:如果Admin Finance上传他们的文档,它会自动创建一个文件夹名称“ Finance”,并将文件上传到该文件夹,但这仅适用于第一次)。 对于上传文件,我使用AjaxUploader。
使用Ajax Uploader在我的上传代码下面:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="FileUpload_Preview.aspx.vb" Inherits="MRISO_FileUpload.FileUpload_Preview" %>
<%@ Register Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" TagPrefix="CuteWebUI" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Upload File</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="../Style/demo.css" />
<script type="text/javascript">
$(function () {
$('.collapse').on('shown.bs.collapse', function () {
$(this).parent().find(".glyphicon-plus").removeClass("glyphicon-plus").addClass("glyphicon-minus");
}).on('hidden.bs.collapse', function () {
$(this).parent().find(".glyphicon-minus").removeClass("glyphicon-minus").addClass("glyphicon-plus");
});
})
</script>
<script type="text/javascript">
$(document).ready(function () {
$('.dataTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "Todo"]]
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#gvFileDetails").prepend($("<thead></thead>").append($(this).find("tr:first"))).dataTable();
$('#gvFileDetails').DataTable();
$('input[type=search]').on("keyup", function () {
var searchTerm = $(this).val();
$(".forHighlight").each(function () {
var searchPattern = new RegExp('(' + searchTerm + ')', 'ig');
$(this).html($(this).text().replace(searchPattern, "<span class = 'highlight'>" + searchTerm + "</span>"));
});
});
});
</script>
<style type="text/css">
body {
font-family: 'Segoe UI';
font-size: 10pt;
}
.highlight {
background-color: yellow;
}
</style>
<script runat="server">
Private Sub InsertMsg(ByVal msg As String)
ListBoxEvents.Items.Insert(0, msg)
ListBoxEvents.SelectedIndex = 0
End Sub
Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
SubmitButton.Attributes("onclick") = "return submitbutton_click()"
End Sub
Private Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
InsertMsg("You have uploaded " & uploadcount & "/" & Uploader1.Items.Count & " files.")
End Sub
Private uploadcount As Integer = 0
Private Sub Uploader_FileUploaded(ByVal sender As Object, ByVal args As UploaderEventArgs)
uploadcount += 1
Dim uploader As Uploader = DirectCast(sender, Uploader)
InsertMsg("File uploaded! " & args.FileName & ", " & args.FileSize & " bytes.")
'Copys the uploaded file to a new location.
args.CopyTo("../Forms/UploadFile/" & args.FileName)
'You can also open the uploaded file's data stream.
'System.IO.Stream data = args.OpenStream()
Dim data As System.IO.Stream = args.OpenStream
End Sub
Protected Overloads Overrides Sub OnPreRender(ByVal e As EventArgs)
SubmitButton.Attributes("itemcount") = Uploader1.Items.Count.ToString()
MyBase.OnPreRender(e)
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="content">
<h2>Upload Your File
</h2>
<p>
This web is using for all Admin department to upload their document.<br /><br />
Regards,<br />
<u><b>JSS</b></u>
</p>
<CuteWebUI:UploadAttachments runat="server" ManualStartUpload="true" ID="Uploader1"
InsertText="Browse Files (Max 20M)" OnFileUploaded="Uploader_FileUploaded">
<ValidateOption AllowedFileExtensions="*.doc, *.docx, *.xls, *.xlsx, *.ppt, *.pptx, *.pdf" MaxSizeKB="20480" />
</CuteWebUI:UploadAttachments>
<p>
<asp:Button ID="SubmitButton" Text="Upload" CssClass="btn btn-success" OnClick="SubmitButton_Click" runat="server" />  
<asp:Button ID="btnCancel" Text="Back to Home" CssClass="btn btn-success" runat="server" />
</p>
<p>
<asp:ListBox ID="ListBoxEvents" runat="server"></asp:ListBox>
</p>
<script type="text/javascript">
function submitbutton_click() {
var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');
var uploadobj = document.getElementById('<%=Uploader1.ClientID %>');
if (!window.filesuploaded) {
if (uploadobj.getqueuecount() > 0) {
uploadobj.startupload();
}
else {
var uploadedcount = parseInt(submitbutton.getAttribute("itemcount")) || 0;
if (uploadedcount > 0) {
return true;
}
alert("Please browse files for uploading");
}
return false;
}
window.filesuploaded = false;
return true;
}
function CuteWebUI_AjaxUploader_OnPostback() {
window.filesuploaded = true;
var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');
submitbutton.click();
return false;
}
</script>
</div>
<hr />
<%-- This tab is displayed the uploaded data and categories by Department --%>
<div id="gridview" class="content">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#menuOne">
<span class="glyphicon glyphicon-minus"></span>
General Department
</a>
</h4>
</div>
<div id="menuOne" class="panel-collapse collapse in">
<div class="panel-body">
<asp:ScriptManager ID="Script1" runat="server"></asp:ScriptManager>
<asp:GridView ID="gvFileDetails" AutoGenerateColumns="false" CssClass="table table-bordered" AllowPaging="true" PageSize="100" EmptyDataText="No File Uploaded" runat="server">
<Columns>
<asp:TemplateField HeaderText="No" ItemStyle-Width="50px">
<ItemTemplate>
<%#(gvFileDetails.PageSize * gvFileDetails.PageIndex) + gvFileDetails.Rows.Count + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Text" HeaderText="File Name" ItemStyle-CssClass="forHighlight" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="50%" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" Text="Download" CommandArgument='<%# Eval("Value") %>' OnClick="DownloadFile" runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" Text="Delete" CommandArgument='<%# Eval("Value") %>' OnClick="DeleteFile" OnClientClick="return confirm('Are you sure want to delete this file?')" runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="hlOpen" Text="View" NavigateUrl='<%# Eval("Value", "~/ViewPage.aspx?fileName={0}") %>' Target="_blank" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#menuTwo">
<span class="glyphicon glyphicon-plus"></span>
Tab Kedua
</a>
</h4>
</div>
<div id="menuTwo" class="panel-collapse collapse">
<div class="panel-body">
This tab is empty. Waiting for the data...
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#menuThree">
<span class="glyphicon glyphicon-plus"></span>
Tab Ketiga
</a>
</h4>
</div>
<div id="menuThree" class="panel-collapse collapse">
<div class="panel-body">
This tab is empty. Watingn for the data...
</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
下面是创建文件夹代码:
Dim path As String = "F:\Upload Document Dept\ " & Session("profile")
If Not (Directory.Exists(path)) Then
Directory.CreateDirectory(path)
lblMsg.Text = "Folder Succesfully create."
Else
lblMsg.Text = "Directory already exists."
End If
我不知道如何使它协同工作,就像我上面说的那样。请帮助我。谢谢:)