Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
code behind ...........

XML
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class fileupload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnsave_Click(object sender, EventArgs e)
    StringBuilder sb = new StringBuilder();
   if (FileUpload1.HasFile)
   {
      try
      {
      sb.AppendFormat(" Uploading file: {0}",
                                  FileUpload1.FileName);
      //saving the file
      FileUpload1.SaveAs("<c:\\SaveDirectory>" +
                                  FileUpload1.FileName);
      //Showing the file information
      sb.AppendFormat("<br/> Save As: {0}",
                         FileUpload1.PostedFile.FileName);
      sb.AppendFormat("<br/> File type: {0}",
                         FileUpload1.PostedFile.ContentType);
      sb.AppendFormat("<br/> File length: {0}",
                         FileUpload1.PostedFile.ContentLength);
      sb.AppendFormat("<br/> File name: {0}",
                         FileUpload1.PostedFile.FileName);
      }
      catch (Exception ex)
      {
      sb.Append("<br/> Error <br/>");
      sb.AppendFormat("Unable to save file <br/> {0}",
                         ex.Message);
      }

   else
   {
      lblmessage.Text = sb.ToString();
   }
}


error is


Error 3 ; expected E:\mine\WebSite19\fileupload.aspx.cs 17 61 WebSite19
Error 18 A namespace does not directly contain members such as fields or methods E:\mine\WebSite19\fileupload.aspx.cs 38 7 WebSite19
Error 6 Invalid token '(' in class, struct, or interface member declaration E:\mine\WebSite19\fileupload.aspx.cs 23 22 WebSite19


Error 19 Type or namespace definition, or end-of-file expected E:\mine\WebSite19\fileupload.aspx.cs 49 1 WebSite19
Posted
Updated 12-Sep-14 19:29pm
v2

1.Your approach for manage the upload is not OK. You are trying to build a string builder based on the file info, then you forgot to use the result by setting result to your label. You should use the result of your string builder also for IF branch.

2.The next line of code:
C#
FileUpload1.SaveAs("<c:\\SaveDirectory>" + FileUpload1.FileName);

must be change in:
C#
FileUpload1.SaveAs("c:\\SaveDirectory" + FileUpload1.FileName);


3.For more details see the next links:
http://msdn.microsoft.com/en-us/library/aa479405.aspx[^]
File Upload with ASP.NET[^]
 
Share this answer
 
i solved my self only .........
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900