我的 asp.net 页面中有一个 FileUpload 控件,它应该将我的图片上传到主机上的某个文件夹中。我设置了一个条件,即当它有文件时,它开始上传。这是代码。
if (File2.HasFile)
{
string b = File2.FileName.ToString();
File2.PostedFile.SaveAs(path + File2.FileName);
}
但条件永远不会为真。我在该页面中还有另外两个 FileUpload。它们工作正常。但这个工作不正常,条件总是为假。我应该怎么办?
这是 HTML 代码:
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<table cellpadding="0" cellspacing="0" class="style4" dir="rtl"
style="border: thin solid #008080">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<div style=" border-width: thin; border-color: #008080; border-left-style: solid;">
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource4"
ForeColor="#333333" GridLines="None" onrowcommand="GridView2_RowCommand"
PageSize="6" Width="130px" Height="200px" ShowHeader="False">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument='<%#Eval("PID") %>' CommandName="LnkEdit"
Text='<%#Eval("Pname") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
</div>
<asp:Label ID="Label18" runat="server"></asp:Label>
</td>
<td>
<div style="float :right">
<table cellpadding="0" cellspacing="0" style="width: 500px">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="نام"></asp:Label>
</td>
<td align="right">
<asp:TextBox ID="TxTEditname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label15" runat="server" Text="زبان"></asp:Label>
</td>
<td align="right">
<asp:DropDownList ID="DropDownList4" runat="server">
<asp:ListItem Value="en">English</asp:ListItem>
<asp:ListItem Value="fa">فارسی</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="توضیحات"></asp:Label>
</td>
<td align="right">
<asp:TextBox ID="TxTEditdes" runat="server" Height="102px"
TextMode="MultiLine" Width="380px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label19" runat="server" Text="عکس جدید"></asp:Label>
</td>
<td align="right">
<asp:FileUpload ID="File2" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="ثبت تغییرات" />
</td>
<td>
<asp:Label ID="Label17" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>