1

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.

2
  • Just to clarify are you trying to open a file using the SPItem.ID? Or am I way off base...
    – BlueBird
    Commented Apr 5, 2013 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
    Commented Apr 5, 2013 at 16:10

2 Answers 2

1

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."

Solution:
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.

1
  • Actually to avoid name changing issue I was searching for ID.
    – MAK
    Commented Apr 9, 2013 at 6:26
0

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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