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: Cannot Upload image using code in a Custom Web Part Options · View
Sree
#1 Posted : Friday, October 05, 2012 4:56:31 PM
Rank: Newbie

Groups: Registered

Joined: 10/5/2012
Posts: 5
Location: Waltham Ma
We are using a trail version of the artfulbits image upload

Trying to assign values to the Image Upload column in a custom webpart using FileUpload asp.net control on it.


Tried the code mentioned in the previous forum referenced below is not uploading images into sharepoint.But the code is getting executed without any errors

http://www.artfulbits.co....aspx?g=posts&t=275

Thanks
stets
#2 Posted : Wednesday, October 10, 2012 12:31:13 PM
Rank: Developers Team

Groups: Registered

Joined: 5/27/2010
Posts: 80
Location: Lviv
Hi Sree,

We have checked the following code to upload images from custom web part, and it is working on our side:

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, let me know your code and Image Upload column settings.
Sree
#3 Posted : Wednesday, October 10, 2012 4:02:36 PM
Rank: Newbie

Groups: Registered

Joined: 10/5/2012
Posts: 5
Location: Waltham Ma
Hi Stets,

Thanks for the reply

Below is the code
Code:

SPSite oSite = SPContext.Current.Site;
SPWeb oWeb = oSite.RootWeb;
SPList oList = oWeb.Lists["Contacts"];
SPListItemCollection listItems = oList.Items;
bool allowUnsafeUpdates = oWeb.AllowUnsafeUpdates;
oWeb.AllowUnsafeUpdates = true;
SPListItem item = listItems.Add();
SPFieldMultiColumnValue columnValue = new SPFieldMultiColumnValue(2);
columnValue[0] = fuphoto.UniqueID; // (Fuphoto is the FileUpload control
columnValue[1] = ""; // Image description
columnValue[2] = "upload"; //IMPORTANT! This value should not be changed
item["Photo"] = columnValue;//Photo is the Column Name
item.update();

Column Settings
Additional Column Settings :
Required Column No
Image Upload Special Settings:
Choose all the extensions and resize large images was set to No

I used the default settings given by the Image upload type.
stets
#4 Posted : Thursday, October 11, 2012 12:26:41 PM
Rank: Developers Team

Groups: Registered

Joined: 5/27/2010
Posts: 80
Location: Lviv
There is some mistake in your code. Try the following:
Code:
SPFieldMultiColumnValue columnValue = new SPFieldMultiColumnValue(3);

instead of
Code:
SPFieldMultiColumnValue columnValue = new SPFieldMultiColumnValue(2);
.

Let me know the result.
Sree
#5 Posted : Thursday, October 11, 2012 3:28:01 PM
Rank: Newbie

Groups: Registered

Joined: 10/5/2012
Posts: 5
Location: Waltham Ma
Tired with 3 columnvalue as well but cannot get it working
Code:

SPFieldMultiColumnValue columnValue = new SPFieldMultiColumnValue(3);


FileUpload Control is in Ajax UpdatePanel will that make any difference?

FYI:using IE8
Sree
#6 Posted : Thursday, October 11, 2012 6:41:40 PM
Rank: Newbie

Groups: Registered

Joined: 10/5/2012
Posts: 5
Location: Waltham Ma
I also observed that the fileupload control "PostedFile" property is returning "Null" always.
Sree
#7 Posted : Friday, October 12, 2012 8:31:33 PM
Rank: Newbie

Groups: Registered

Joined: 10/5/2012
Posts: 5
Location: Waltham Ma
Got the File Upload control working...

This is an issue with the File Upload control used with UpdatePanel. Partial Page rendering is returning null from FileUpload.Postedfile is always null.

I used triggers in updatepanel for the upload button to solve this issue.

Thanks for the help Stets
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.