rachayita jaiswal

rachayita jaiswal

  • NA
  • 217
  • 106.2k

Fileuplaod in asp.net

Feb 25 2014 12:00 AM
Hi,
 
I have file uplaod and button, but when I am selecting a image and click on button on my code behind file name is coming blank----
 
aspx page:
 
<tr>
<td><font color="red">*</font>Logo</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
&nbsp;<asp:Label ID="lbl_imgupload" runat="server" style="color :Red"></asp:Label>
</td>
</tr>
 
<asp:UpdatePanel ID="updatePanelAction" runat="server" UpdateMode="Always">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn_comp_submit" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="btn_comp_submit" Text="Submit" runat="server" OnClick="btn_comp_submit_Click" />&nbsp;
</ContentTemplate>
</asp:UpdatePanel> 
 
aspx.cs page
 
 protected void btn_comp_submit_Click(object sender, EventArgs e)
{
try
{
if ((FileUpload1.FileName != ""))
{
byte[] raw;

string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
if (((extension == ".jpg") || ((extension == ".gif") || (extension == ".png"))))
{
FileStream fs = new FileStream(FileUpload1.PostedFile.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
raw = new byte[fs.Length];
fs.Read(raw, 0, Convert.ToInt32(fs.Length));
...................................................................................
 
Please tell me the prob, Ihave used file upload before also but never faced this type of issue.
 

Answers (2)