Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

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

  Date: Feb 20    Category: Sharepoint    Views: 2599


I have a C# custom web part that UPLOADS documents > 5Meg to an SHARED 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();

Share: 

 

No Answers Found. Be the First, To Post Answer.

 




Tagged: