Multi sourced document library.... More Info

hi,

i have a requirement for a document library where some of the entries are in sharepoint, and others are actually hyperlinks to content in another, non-sharepoint, web site. That is, one item in the document library is a normal sharepoint lodged document, whilst the next is really just the meta-data with the URL pointing outside of SP and when you click on it you go there. Its sort of like combining a document library list and a links list in one.

I have tried programatically adding new items to the document library which are external URL's. This doesnt work, it just loads the file into SP.

I have also tried altering an existing item and changing its "URL Path" field. This doesnt work also as it appears to be a read only field.

Does anyone have a clue how to try to do this? Is there some other approach?

Thanks in advance,

Ross

[909 byte] By [RossWilliamNelson] at [2008-1-6]
# 1

Hi,

since above post ive managed to configure a document library with two content types, both documents and links which exactly what i want. Now i want to be able to create the links programatically as stated above. I have the below but I get an exception on the line below marked BANG!!! which has the message:

"To add an item to a document library, use SPFileCollection.Add()

SPSite mySiteCollection = new SPSite("http://cbr02dw2295752:37121/");

SPWeb mySite = mySiteCollection.AllWebs["Case-2007071"];

SPList list = mySite.Lists["Shared Documents"];

SPListItemCollection listItems = list.Items;

SPFieldUrlValue fuv = new SPFieldUrlValue();

fuv.Description = "Something";

fuv.Url = "http://cbr02dw2295752:31145/fred.doc";

SPContentType spt = list.ContentTypes["Link to a Document"];

SPListItem newItem = list.Items.Add();

newItem["ContentTypeId"] = spt.Id;

newItem.Update(); // BANG!!!

newItem["URL"] = fuv;

newItem["Name"] = "My2ndRecord";

newItem.Update();

Does anyone know how to create document links, rather than documents, in a document library. I cant figure out any parameters to SPFileCollection.Add that are at all useful and the doco is pretty limited at the moment. The above code also does not seem to work for document libraries. I have also tried using SPDocumentLibrary casts from SPList but it makes no difference.

HELP PLEASE!!!! Smile

RossWilliamNelson at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 2
Did you end up solving this problem? maybe some else has a solution?
BobSaget at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 3
I've been looking for a solution for this for months. Anyone?
rbb at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 4
I do not have a source code for this, but here is the direction. You have to add new SPFile to the document library. It must contain HTML code with link to external URL. You can use page refresh written in javascript or simply META-REFRESH tag. Please post the results.
DB_1234 at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 5

Guys

I "reflected" how the Sharepoint team did it and heres the method to add a link. They bascially create an ASPX page on the fly and add it to the document lib. Inside that file it simply does a redirect, using a "SharePoint:UrlRedirector"..Bit wierd but ingenious!

public void onOK(object sender, EventArgs e) { SPContentTypeId id = new SPContentTypeId(base.Request.QueryString["ContentTypeID"]); SPContentType type = this.CurrentList.ContentTypes[id]; SPFolder currentFolder = this.CurrentFolder; SPFileCollection files = currentFolder.Files; string urlOfFile = currentFolder.Url + "/" + this.NameInput.Text + ".aspx"; string format = "<%@ Assembly Name='{0}' %>\r\n <%@ Register TagPrefix='SharePoint' Namespace='Microsoft.SharePoint.WebControls' Assembly='Microsoft.SharePoint' %>\r\n <%@ Import Namespace='System.IO' %>\r\n <%@ Import Namespace='Microsoft.SharePoint' %>\r\n <%@ Import Namespace='Microsoft.SharePoint.Utilities' %>\r\n <%@ Import Namespace='Microsoft.SharePoint.WebControls' %>\r\n <html>\r\n <Head> <META Name='progid' Content='SharePoint.Link'>\r\n <body>\r\n <form id='Form1' runat='server'>\r\n <SharePoint:UrlRedirector id='Redirector1' runat='server' />\r\n </form>\r\n </body>\r\n </html>"; StringBuilder builder = new StringBuilder(format.Length + 400); builder.AppendFormat(format, typeof(SPDocumentLibrary).Assembly.FullName); SPFile file = files.Add(urlOfFile, new UTF8Encoding().GetBytes(builder.ToString()), false); SPListItem item = file.Item; item["ContentType"] = type.Name; item["URL"] = this.UrlInput.Text + ", "; item.UpdateOverwriteVersion(); if (this.numFields_NoTitle(type) <= 2) { if (file.CheckOutStatus != SPFile.SPCheckOutStatus.None) { file.CheckIn(""); } } else { SPUtility.Redirect(currentFolder.ServerRelativeUrl + "/Forms/EditForm.aspx" + string.Concat(new object[] { "?Mode=Upload&CheckInComment=&ID=", item.ID, "&Source=", base.Request.QueryString["Source"], "&RootFolder=", currentFolder.ServerRelativeUrl }), SPRedirectFlags.Static, this.Context); return; } SPUtility.Redirect(null, SPRedirectFlags.UseSource, this.Context); }

Markqjones at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...

SharePoint Products and Technologies

Site Classified