Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to use a link button inside of a gridview to redirect to a specific document in sharepoint based on what link they click. the code is as follows:

site = new SPSite("https://c27ipacpndl103w/intranet.manpower...").openweb();
spfolder folder = site.getfolder("https://c27ipacpndl103w/intranet.manpower...");
spfile file = site.getfile("https://c27ipacpndl103w/intranet.manpower...");

understand for security reasons I've left out some information but on the spsite I have the base site document library that contains the folder for the file. in spfolder, I have the url for the folder, and spfile is the near exact url for the document (save for a wild card near the end which is built like this:
spfile file = site.getfile("https://c27ipacpndl103w/intranet.manpower..." ... + udyear + "*.pdf");

the "*" is a wild card because the very last part before pdf is indeterminable without a few more hundred lines of code) any assistance with this issue would be greatly appreciated and if any more information is required, please let me know. thank you.

I think it is obvious what the question is but I'll spell it out.
How do I programmatically open a file in sharepoint? I keep getting a url not found error and I've compared the url's and they are exactly the same except the end it puts the "*" in the url.
Updated 27-Oct-11 11:12am
[no name] 27-Oct-11 14:31pm    
You forgot to include an actual question. What is it you are having difficulties with?

Is this page where this gridview is located in SharePoint, as in an Application Page, or it being used in an external site?
[no name] 27-Oct-11 18:06pm    
No the question was not obvious. Please remember we are not sitting next to you.

1 solution

Where are you trying to use this code? Which line is throwing the exception? I would guess it is the very first line but please confirm.

GetFile takes a relative url not an absolute as you are trying. Also, you should be properly disposing your objects.
Share this answer
Sean8084 27-Oct-11 18:53pm    
it doesn't say what line is throwing the error, just says that I should check my url or if I clicked a link, that it may be outdated. what do you mean that getfile takes a relative url? how would it work if it isn't looking to the exact location? sorry for my hostility in my revision, have been getting pushed to get this project done and haven't been able to figure it out (this is always a last resort as it usually takes all day to get any responses)
[no name] 27-Oct-11 19:14pm    
Have you debugged this? That would tell you what line the problem is on. How else do you expect to solve your problem, try random solutions until one works?

I know GetFile takes a relative url because I've read the documentation. I would do that before using CodeProject as a last resort.

You still have not answered the question. Where are you trying to use this code? Is it within a SharePoint application? Is it a web application running on the SharePoint machine? That is the only place you will be able to use server object model code.

Have you used SharePoint before?

Sean8084 28-Oct-11 11:53am    
it comes back a bad url meaning that the url that it tries to open is an incorrect url, meaning it doesn't exist. and I didn't ask how you knew it was relative, I asked what you meant. and it's in a web application with what should be all necessary using statements. you're talking to me like I'm stupid when I know you know exactly how to help me with my question. thank you.
[no name] 28-Oct-11 11:54am    
If you feel you are being treated as stupid I apologize. However, you are not providing enough useful information and the usage of the methods you provided show ignorance of the API. Showing the actual code you are using and having difficulty with, rather than a few lines that are perhaps out of context, will help to prevent this view.
You also show ignorance of proper debugging techniques when saying "it doesn't say what line is throwing the error"

As I have said, you can only use the Server Object Model code within a SharePoint environment or in an application on the SharePoint machine. With 2010 it also can only be used in a 64-bit application.

I don't know exactly how to help you because you have been unclear and have not answered my questions. I understand you are under some stress to deliver this project but the higher quality your responses are the better we will be able to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900