Click here to Skip to main content
15,897,141 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have a DataAccessLayer (Class) called SmartVote.cs but i didn't use it. here is my code
that i coded behind the form AddPicture.aspx

C#
// Read the file and convert it to Byte Array
string filePath = FileUpload2.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = String.Empty;

//Set the contenttype based on File Extension
switch (ext)
{


    case ".doc":
        contenttype = "application/vnd.ms-word";
        break;
    case ".docx":
        contenttype = "application/vnd.ms-word";
        break;
    case ".pdf":
        contenttype = "application/vnd.ms-word";
        break;

}
if (contenttype != String.Empty)
{

    Stream fs = FileUpload1.PostedFile.InputStream;
    BinaryReader br = new BinaryReader(fs);
    Byte[] bytes = br.ReadBytes((Int32)fs.Length);

    //insert the file into database
    string strQuery = "insert into PARTY(Party_Manifesto)" +
       " values (@Party_Manifesto)";
    SqlCommand cmd = new SqlCommand(strQuery);
    //cmd.Parameters.Add("@Candidate_Image", SqlDbType.VarChar).Value = filename;
    //cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value
    //  = contenttype;
    cmd.Parameters.Add("@Party_Manifesto", SqlDbType.Binary).Value = bytes;
    InsertUpdateData(cmd);
    lblmsg.ForeColor = System.Drawing.Color.Green;
    lblmsg.Text = "File Uploaded Successfully";
}
else
{
    lblmsg.ForeColor = System.Drawing.Color.Red;
    lblmsg.Text = "File format not recognised." +
      " Upload document/pdf/doc/docs formats";
}


Please help

-SA
Posted
Comments
José Amílcar Casimiro 18-Jun-13 10:25am    
Your question makes no sense. What is your problem?
[no name] 18-Jun-13 10:36am    
are you familiar with DataAccessLayer? if you are familiar with it you will understand that on a DAL u write the method like DeleteUser() and then behind the form you will call the method. so is the same principle with my problem. I want to remove the INSERT STATEMENT from my code to DAL and call it as a method not the way i wrote it on my problem, i want my code to look profetional when m presenting it.
José Amílcar Casimiro 18-Jun-13 10:40am    
So...what is your problem? Create a method in your SmartVote.cs to insert the file into the database, that accepts a parameter with the file content (byte array).

1 solution

You have the method. Just copy it in to the DAL and call it from there. I don't see what the issue is.
 
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