Thursday, May 3, 2012

[sharepointdiscussions] Digest Number 4436

Messages In This Digest (1 Message)

Message

1.

C# - custom web part to post "Link To A Document" content type

Posted by: "rjohnandmore" rjohnandmore@yahoo.com   rjohnandmore

Wed May 2, 2012 10:50 am (PDT)



Hello! I have a C# custom web part that unloads documents > 5Meg to an Sahre Drive. This web part creates a :Link to a Document" content type entry in the document library.

As usual, the web part works PERFECT on MY development machine :0) However, as soon as we load it to TEST it errors out when it attempts to update the -- item["URL] = myShareURL

I am also using SPSecurity.RunWithElevatedPrivileges(delegate() and have verified that I am using "System Account"

That error usually occurs when the "Link to a Document" Content Type has not been enabled for that Library; but it has been. I CAN create an entry using that Content Type via the browser in the library.

Been stumped for 2 days now. Have even tried it on 2 different servers with the SAME result: No Go.

Any ideas???? I cant see how it is the code -- but here is the specific section:

//Create SPFile object
SPFile uploadFile = null;
uploadFile = myLibrary.Files.Add(oWeb.Site.Url + "/" + urlOfFile, new MemoryStream(new UTF8Encoding().GetBytes(redirectPageHTML.ToString())), true);

// Create SPField onject
SPListItem item = uploadFile.Item;

//Update Content Type
fieldName = "Content Type";
fieldValue = "Link to a Document";
item["Content Type"] = fieldValue;

//Update File Share URL
fieldName = "URL";
fieldValue = myShareURL
item["URL"] = fieldValue;

//Commit changes
item.Update();

Recent Activity
Visit Your Group
New business?

Get new customers.

List your web site

in Yahoo! Search.

Y! Messenger

PC-to-PC calls

Call your friends

worldwide - free!

Yahoo! Groups

Parenting Zone

Family and home

Tips for mom

Need to Reply?

Click one of the "Reply" links to respond to a specific message in the Daily Digest.

Create New Topic | Visit Your Group on the Web

No comments: