AsyncFileUpload in three tier architecture

Hi Experts,
I am using AsyncFileUpload.My project has three tier architecture.
I am storing image name in database and storing image in folder on the server.
I am following 3 tier architecture.

In my code
MyEmployee oEmployee = new MyEmployee();
 if (AsyncFileUpload1.HasFile)
                {
                    oEmployee.ImageName = Convert.ToString(AsyncFileUpload1.FileName);
                }



In Employee.cs
  public string ImageName
          {
              get
              {
                  return _imageName;
              }
              set
              {
                  _imageName = value;
              }
          }


Then in datalayer I am accessing this property

 sqlParams[41] = DBDataHandler.GetSqlParameter("@Photo", objEmployee.ImageName, SqlDbType.VarChar);



But I am confused,how should I upload the image in the folder on server?
How do I follow this technique.
Your help is really appreciated.
Thanks in advance.
LVL 8
Johny BravoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ivo StoykovCommented:
try something like

HTH

Ivo Stoykov

string filename  = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
AsyncFileUpload1.SaveAs(Server.MapPath("Uploads/") + filename); 
if(!String.IsNullOrEmpty(filename)) {   oEmployee.ImageName = filename; }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Johny BravoAuthor Commented:
Hmm ok so I don't need to go to DataLayer for storing images. Right?
One more thing,I am changing file name of the uploaded file.
strUploadFolder = Request.PhysicalApplicationPath + "../Images/EmployeePics\\";
                    strExtension = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName);
                    AsyncFileUpload1.SaveAs(strUploadFolder + "Test" + extension);

Here instead of "Test" ,I want to add name of the username which he enters in the textbox.
txtFirstName.Text + txtLastName.Text.

How to do this?
0
masterpassCommented:
you don't have to do that in DataLayer .. can do it in the UI Layer itself ...

Here instead of "Test" ,I want to add name of the username which he enters in the textbox.
txtFirstName.Text + txtLastName.Text.


string FileNameToSave = txtFirstName.Text + txtLastName.Text+extension;
AsyncFileUpload1.SaveAs(Server.MapPath(System.IO.Path.Combine(strUploadFolder , FileNameToSave)));

Open in new window

0
masterpassCommented:
forgot to update the first line

Here is the updated code
strUploadFolder = "Images\EmployeePics";\\When you are giving like this the Image folder should be in the root of the project, If it's not then correctlt specify the path here 
strExtension = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName);
string FileNameToSave = txtFirstName.Text + txtLastName.Text + extension;
AsyncFileUpload1.SaveAs(Server.MapPath(Path.Combine(strUploadFolder , FileNameToSave)));

Open in new window

0
Johny BravoAuthor Commented:
As both solutions helped me so I am distributing points.
Thanks a lot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.