简体   繁体   English

如何在服务器端C#(asp.net网站)中为文件上传分配文件

[英]How to assign a file to file upload in server side c# (asp.net website)

I have a asyncfile upload in my asp.net website. 我在asp.net网站上上传了一个asyncfile。 I have to show a file name inside the file upload. 我必须在文件上传中显示文件名。 I have a edit functionailty which has to display the name of uploaded file insided the file upload. 我有一个编辑功能,该功能必须在文件上传中显示上传文件的名称。 I just want to show the file name which i have it during page load, How can I assign the file name to the file upload in server side(c#) And how to change the backcolor of the file upload from server side. 我只想显示页面加载过程中拥有的文件名,如何在服务器端将文件名分配给文件上传(c#),以及如何更改从服务器端上传的文件的背景色。

 <asp:AsyncFileUpload ID="AFU_Doc"  ErrorBackColor="Red" OnUploadedComplete="btnDocUpload_Click"
        runat="server" UploaderStyle="Traditional" ThrobberID="aajaxLoader" />

For Security reason we can't assign file name to file upload control in html or i asp.net 出于安全原因,我们无法为html或i asp.net文件上传控件分配文件名

To achieve this assign a label in place of file upload control and bind the file name to label and hide the file upload control 为此,请在文件上传控件的位置分配标签,并将文件名绑定到标签,然后隐藏文件上传控件

IF user want to upload new file then assign delete image near it and on click hide label and show file upload control and upload the file 如果用户要上传新文件,然后在其附近分配删除图像,然后单击“隐藏标签”并显示文件上传控件并上传文件

You can hide and show following control as per your requirement in client side or sever side. 您可以根据需要在客户端或服务器端隐藏和显示以下控件。

<input type="file" id="txtFileUploadGrid" runat="server" />

<asp:Label ID="lblFromFileName1" runat="server"></asp:Label>

<asp:ImageButton ID="btnRemove" CommandName="Remove" runat="server" ToolTip="Remove Zip" ImageUrl="~/CommonContent/Images/delete.png" />

That is not possible. 这是不可能的。 With AsyncFileUpload , the FileName property is read-only. 使用AsyncFileUploadFileName属性为只读。

I assume this is to avoid hidden file uploads. 我认为这是为了避免隐藏文件上传。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM