whitespace COMPANY whitespace SERVICES whitespace PRODUCTS whitespace PURCHASE whitespace SUPPORT whitespace CONTACTS whitespace Home whitespace Contact Us whitespace Site Map whitespace
whitespace
SUPPORT
whitespace
FORUM
whitespace
FAQS
whitespace
SUBSCRIPTION
whitespace
REQUEST ON-LINE
whitespace
whitespace

Technical Support Forum

Welcome Guest Search | Active Topics | Log In | Register

Image Upload From code behid Options · View
mohan_sg
#1 Posted : Friday, February 18, 2011 7:24:10 AM
Rank: Newbie

Groups: Registered

Joined: 2/18/2011
Posts: 2
Hi,

I would like to know how can we use c# code behind to upload pictures to Image Upload Control.
Eugene
#2 Posted : Friday, February 18, 2011 1:17:51 PM
Rank: Guest

Groups:

Joined: 7/9/2009
Posts: 3,341
Hi,

Yes, you can use code behind to upload pictures.
Below is sample C# code you can use as a reference:
Code:
using( SPSite site = new SPSite( "http://siteurl/" ) )
{
    using( SPWeb web = site.OpenWeb() )
    {
        bool allowUnsafeUpdates = web.AllowUnsafeUpdates;
        web.AllowUnsafeUpdates = true;

        SPList list = web.Lists["ListWithImageColumn"];
        SPListItem item = list.Items[0];

        SPFieldMultiColumnValue columnValue = new SPFieldMultiColumnValue( 3 );
        columnValue[0] = FileUpload1.UniqueID; // FileUpload control UniqueID
        columnValue[1] = "Some Image Description"; // Image description
        columnValue[2] = "upload"; //IMPORTANT! This value should not be changed
           
        item["ImageUploadColumnName"] = columnValue;
        item.Update();

        web.AllowUnsafeUpdates = allowUnsafeUpdates;
    }
}

Please note that you have to reference file upload control from the page. Such code can be inserted into Button_Click handler for example.
mohan_sg
#3 Posted : Sunday, February 20, 2011 5:21:28 AM
Rank: Newbie

Groups: Registered

Joined: 2/18/2011
Posts: 2
Hi,

Thanks for the above code. i need some more additional information. My situation is that i need to create a exe file that reads the images from a folder and upload to an sharepoint list.

In the above sample you have specified using FileUpload control. do you have any sample without using FileUpload control
Eugene
#4 Posted : Monday, March 07, 2011 11:23:37 AM
Rank: Guest

Groups:

Joined: 7/9/2009
Posts: 3,341
Hi,

Unfortunately this is not possible with current implementation.
Image Upload works internally with data stream provided by file upload control. So, scenario described in this thread will work from web applications only.
This will not work for standalone back end exe with direct access to files.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Company | Services | Practices | Technologies | Career | Contacts | Privacy
© 2005-2016 ArtfulBits. All rights reserved.