Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

My specifications:

Windows Server 2003
Visual Studio 2008
Windows Sharepoint Services 3.0
visual studio 2008 extension for Sharepoint services 3.0

I'm creating a web part with a SPGridView. I want one of the columns of the SPGridView to display links to documents of SharedDocumentLibrary.

How to read contents of SharedDocumentLibrary and display them as links in my webpart ?

I think we can achieve this through 'Link to Document' feature of SharePoint. But I don't know how? Can somebody give me some example.

My requirement is exactly this. Linking documents in SharePoint. How do I achieve it through source code ?

share|improve this question
add comment

3 Answers

You could develop a web-part in Visual Studio which gets the list or document library you need and displays the content in a repeater or grid view, if you need an example of how that code might look, see this link.

http://code.msdn.microsoft.com/office/SharePoint-2010-101-Code-da251182

Loads of examples of how to acccess a list using the various ways you can do it..

  1. Web services
  2. JSON
  3. Silverlight etc
  4. Rest
  5. Javascript

Hope this helps.

S

share|improve this answer
    
Thanks for the reply. Its really good list. It could have been better if I could open them in VS2008. :( –  Laxman Mar 19 '13 at 7:00
add comment

When I upload a file to Sharepoint, I save a record in my App's database with the file name and location, usually this will be in the format http://198.mySharepointServer/LibraryName/Filename.txt. This is then much easier and quicker than accessing Sharepoint programatically, running code and then retrieving the files url because you can just access a local database.

Similarly if you have the file's filename and you are only using 1 Sharepoint library the url shouldn't change so you can just use that url throughout and simply attach /filename.txt to the end of that url.

Here's a short extract of some code I used to retrieve the url programatically by searching with a document ID. Please note this was coded by a colleague so I just followed the logic, you can do the same and see what pieces you could use.

using (ClientContext spclient = new ClientContext(libraryUrl))
{
    CamlQuery query = new CamlQuery();
    try
    {
    libraryName = Properties.Settings.Default.Members;
    spclient.Credentials = creds;
    Web site = spclient.Web;
    List docList = site.Lists.GetByTitle(libraryName);

    spclient.Load(docList.Fields);
    spclient.ExecuteQuery();

    var filterList = new FilterOptionList();
    var DocID = new FilterOptions();
    AddFilters(spclient, docList, filterList, DocID, new string[] { DocumentID }, "Doc Ref No");

    StringBuilder q1 = new StringBuilder();
    q1.Append(CreateAndSection(filterList));
    queryString.Append(q1.ToString());
    queryString.Append("</Where></Query></View>");
    query.ViewXml = queryString.ToString();
    ListItemCollection collListItem = docList.GetItems(query);

    spclient.Load(collListItem);
    spclient.ExecuteQuery();

    if (collListItem.Count != 0)
    {
    spclient.Load(docList.Fields.GetByTitle("Doc Ref No"));
    spclient.ExecuteQuery();
    var DocRefNumColName = docList.Fields.GetByTitle("Doc Ref No").InternalName;

    foreach (ListItem item in collListItem)
    {
        if (item.FileSystemObjectType == FileSystemObjectType.File)
        {
        spclient.Load(item);
        spclient.Load(item.File);
        spclient.ExecuteQuery();

        domain = item.File.ServerRelativeUrl;
        if (domain != "")
        {
            DocumentURL = libraryUrl + domain;
            IsInMembers = true;
        }
        else IsInMembers = false;
        }
    }
    }                    
    } 
    catch (Exception ex)
    {
        DocumentURL = "";
    }
}         

Please vote as an answer if this helped you.

share|improve this answer
    
Hi, thanks for the reply. I really couldn't understand this code. –  Laxman Mar 20 '13 at 6:17
add comment

In order to to add "Link to document" you need to do a couple things.

1) Turn ON the "Management of Content Types". This will be in the List/Library Settings -> Advanced Settings -> Allow management of content types? -> Yes

2) Add the content type "Link to a Document". You can go to your List/Library Settings and click Add from existing site content types -> select "Link to Document" then click Add.

3) You can now have a list/library item that links to another document! Go to your list/library and click New Document drop-down in the ribbon, then choose "Link to a Document"

share|improve this answer
    
thanks for the reply. but I want it through source code as I'm developing a web part. –  Laxman Mar 19 '13 at 5:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.