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

I am working on SharePoint Foundation 2010. I want to open file from a link.
I found a solution "Link To Document" content type. But in "Link To Document" content type we need filename of original file.
My Problem :
The filename can be changed any time. If I am using "Link To Document" content type then after changing the name the link will not work because the original filename is changed.
Question:
Can I create a link which will work using ID instead of name?
If yes then how? and if no then What could be the other ways to achieve this requirement?

Please Help.
Thanks.

share|improve this question
    
Just to clarify are you trying to open a file using the SPItem.ID? Or am I way off base... –  BlueBird Apr 5 '13 at 15:03
    
Yes, I want to open the file using SPItem.ID. I want to find the file like we are using ID in URL of EditForm and fetching the data. –  MAK Apr 5 '13 at 16:10

2 Answers 2

My issue resolved. thanks for your effort and reply.

Explanation:

I have "Link to Document" content type. Before asking the question I was thinking that "Link To Document" content type will have link of document Eg: "http://{yourserve}/{documentLibrary}/ABC.txt" . After creating the link, original document name can be changed (i.e. ABC.txt to ABC1.txt ) but the link will be same and on click it will show the error like "File not found."
But after R and D, I found if I am using "Link To Document" content then if file name is changed then link will also change (i.e. Link will be "http://{yourserve}/{documentLibrary}/ABC1.txt"). and resolved my issue.

share|improve this answer
    
Actually to avoid name changing issue I was searching for ID. –  MAK Apr 9 '13 at 6:26

Ok, if you already have SPItem you should be able to get the file using SPItem.File then you have access to all the SPFile properties.

However if you just have the ID and not the SPItem then you should be able to do this:

SPList olist = oWeb.Lists("LongList")
SPItem oitem = oList.GetItemById(123)            
SPFile oFile = oItem.File  

I hope that answers what you are looking for...

share|improve this answer

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.