Click here to Skip to main content
15,892,804 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!
I'm working with a Visual WebPart and i want to upload a image from my fileUpload control to a SharePoint list. This is the code i'm using but i cant get it to work, (Title, prodnum, color, etc is working, but not image).
I've also installed http://www.sparqube.com/SharePoint-Picture-Column/[^]

This is my listview: http://i47.tinypic.com/x5z2v7.jpg[^]
If it's not allowed to upload pictures, please tell me!

Hope to hear from you!

Kind regards,
Kristian.

Code:
C#
protected void Button_Save_Click(object sender, EventArgs e)
{
        SPSite currentSite = SPContext.Current.Site;
        SPList myList =
        currentSite.RootWeb.Lists.TryGetList("SharePointDatabase");

        try
        {
            if (myList != null && FileUpload_Pic.PostedFile != null &&
            FileUpload_Pic.HasFile)
            {
                SPListItem listItem = myList.Items.Add();

                listItem["Title"] = TextBox_Name.Text;
                listItem["ProductNumber"] = TextBox_ProdNum.Text;
                listItem["Color"] = TextBox_Color.Text;
                listItem["ListPrice"] = TextBox_ListPrice.Text;
                listItem["MoreInformation"] = TextBox_MoreInfo.Text;

                string fileName =
                Path.GetFileName(FileUpload_Pic.PostedFile.FileName);
                listItem["Image"] = fileName;

                listItem.Update();



                TextBox_Search.Text = string.Empty;
                TextBox_Name.Text = string.Empty;
                TextBox_MoreInfo.Text = string.Empty;
                TextBox_ProdNum.Text = string.Empty;
                TextBox_Color.Text = string.Empty;
                TextBox_ListPrice.Text = string.Empty;

                Label_Exception.Text = "Saved to Database list.";

                Dispose();
            }
        }
        catch (Exception x)
        {
            Label_Exception.Text = x.Message;
        }
 }
Posted
Updated 27-Nov-12 23:10pm
v3

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