How to get the web of document from the URL

Hi All,
Need small help here,
I have SharePoint doc URL as below:
http://sharepoint.com/sub1/sub2/sub3/documents/TestFile.docx
Here, TestFile existed in document library of Subsite i.e. sub3.
If I give above URL as input, I should be able to get "sub3" web.
How can achieve this programmatically. Overall we should get the leaf web from the URL.
Thanks in advance.
Krishnasandeep

Hi Sanny521,
The SPSite constructor does not care when you pass in the document library and filename as part of the url. you can use the following code:
string myFileUrl = "http://sharepoint.com/sub1/sub2/sub3/documents/TestFile.docx";
using (SPSite site = new SPSite(myFileUrl))
using (SPWeb web = site.OpenWeb())
SPFile file = web.GetFile(myFileUrl);
string webUrl = web.ServerRelativeUrl;
You pass the full url into the SPSIte constructor, it will retrieve the site collection, then the OpenWeb call will retrieve the proper web from the already passed full url, then you can retrieve the file and the url of the SPWeb.
Mathieu Desmarais http://www.matdesmarais.com/

Similar Messages

  • How to get customer number and name from the SD document

    Hi All,
    Can you please let me know how to get Customer Number and Name from the SD Document?
    Thanks a lot....
    Anil

    Hi,
    It will be displayed in the SD (BIlling document) itself,  you clikc on the VF03. The customer name and number will also appear in the SO document also Tcode VA03
    regards,
    radhika
    Edited by: kolipara radhika on Jul 10, 2009 5:32 AM

  • How to find out web-inf path from the physical drive?

    How to find out web-inf path from the physical drive?
    I have some user profiles in web-inf directory.SO I want to know the path from root directory like
    d:/program files/allaire/jrun/appname/web-inf/profiles/username like that.
    Presently I am able to get the path upto the application directory and from that I am concatinationg web-inf/profiles/username .
    But it is giving problems when it is deployed under unix or linux.Because web-inf there it treats as WEB_INF
    SO I want to get the path of web-inf directory with out hard coding.
    Thanku

    String path = application.getRealPath("/WEB-INF/profiles/username");
    Note sure why you need this, but you don't need the real path to read the file - you can get an InputStream using the relative path. See ServletContext getResource() and getResourceAsStream().

  • I broke my iPhone 5 now using a 4 but don't know if or how to get my photos ect..from the 5 to the 4.can I do this and how plse help

    I broke my iPhone 5 now using a 4 but don't know if or how to get my photos ect..from the 5 to the 4.can I do this and how plse help

    Restore the backup of your iPhone 5 to your iPhone 4.  It will contain your camera roll photos. 
    To do this, first make sure the iPhone 4 is running the same or higher version of iOS as your iPhone 5 was.  If it isn't, you'll need to update it first.  Then, to restore the iCloud backup, you'll have to begin by erasing the iPhone 4.  If you have any newer data on the iPhone 4 that is not contained in the iPhone 5 backup, you'll need to save that first.  When you're ready, go to Settings>General>Reset, tap Erase All Content and Settings, then go through the set screens on the iPhone 4 and when given the option, choose Restore from iCloud backup and follow the prompt, choosing the backup of your iPhone 5 to restore to.  Be sure it is connected to wifi and your charger as it is restoring the backup.

  • Problems doing the "Web Service" example from the 2-Day-Developer Guide

    Hello,
    I want to do the "web service" example from the 2-Day-Developer Guide.
    I give the application my proxy server address in the format address:port and go through the assistant creating the web service. After selecting the IBM UDDI-service and searching for %xMethods% as business name I get the following error:
    ORA-31011: XML-Parsing not successful ORA-19202: Error parsing XML LPX-00104: Warning: Element "html" is not declared in DTD Error at line 2
    What have I done wrong?
    With kind regards
    Florian Reiser

    Please.. Could you change your forum handle to something more human, we are a friendly group here and lik to know who we are talking to.. Secondly, WHy are you using such an OLD version oft he product. You would be better off installing 3.2.1 (latest released build) and asking your questions after you do that..
    (I am sorry, it's like asking for help in a Windows support forum about issues you are having with Windows 3.1)
    Thank you,
    Tony Miller
    Webster, TX

  • How do you get the web application path from the servlet?

    I have created a web application which is installed in
    /webapps/myApplication
    /webapps/myApplication/data/users.xml
    /webapps/myApplication/WEB-INF/classes/myServlet
    How can you get the path to the "users.xml" file from the "myServlet" file?
    The code below doen's seem to return the xml file. anybody knows why?
    public class myServlet extends HttpServlet {
    public void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException
    File myXmlFile = new File("/data/users.xml");

    Try this..
    String FileName = getServletContext().getRealPath("\\data\\users.xml");
    File myXmlFile = new File(FileName);
    hope this helps..

  • How do I remove "Recent Items" Documents from the apple menu?

    I've been searching for an answer to this question for the better part of 3 hours now.  W
    Several iterations of osx ago, there was the ability to separately limit how many recent items were shown for Applications, Documents and Servers.  Over the years, I simply installed a newer version of osx on top, and surprisingly my recent items always eliminated the Documents from the list. 
    I've since done a clean install of mavericks after installing an SSD, and i've lost this small but important part of my work flow.  No matter what I've tried to remove the documents from Recent Items, it always shows up.  I can still boot into my old HDD (which is now installed as a supplementary drive and also updated and running mavericks 10.9.2), and see from clicking on the Apple Menu > Recent Items that it only displays Applications and Servers.
    Try as hard as I can, I can't simply figure out how to remove the documents from the recent items menu.  I've tried editing the com.apple.recentitems.plist file, to show 0 items for documnets, but this never seems to work.  (I've since read that this file is simply rewritten on logout.) Strangely, if I go into the old setup System Preferences, Recent Items:  it is showing as None.  I also suspect that maybe I used Tinker Tools or some other utility to change some command line preference (using the gui) several years back.  Not sure how I could investigate what would need to be done to compare files or otherwise figure out how to remove the documents section from the recent items menu.
    It's starting to drive me crazy.  Anyone?

    The Apple menu is at the top left hand corner of your screen, click on it and about this Mac is the first choice.
    Click twice on Version to get serial number.

  • How do you open a new document from the template chooser?

    Hi There,
    Since upgrading to Yosemite, I can't find the option to open a new document from the template chooser. When I type in "template" in the help box it shows it under "file" But when I click on "File" I don't see that option.
    Basically, I'm trying to ask how do you access the templates in the new pages?
    Thanks so much

    Check your preferences and make sure Show Template Chooser is selected:
    Then just choose New from the File menu.

  • How to get server data without reading from the socket stream?

    My socket client checks for server messages through
                while (isRunning) { //listen for server events
                    try {
                            Object o = readObject(socket); //wait for server message
                                tellListeners(socket, o);
                    } catch (Exception e) {
                        System.err.println("ERROR SocketClient: "+e);
                        e.printStackTrace();
                    try { sleep(1000); } catch (InterruptedException ie) { /* ignore */ }
                }//next client connectionwith readObject() being
        public Object readObject(Socket socket) throws ClassNotFoundException, IOException {
            Object result = null;
    System.out.println("readObject("+socket+") ...");
            if (socket != null && socket.isConnected()) {
    //            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                ObjectInputStream ois = new ObjectInputStream(new DataInputStream(socket.getInputStream()));
                try {
                    result = ois.readObject();
                } finally {
    //                socket.shutdownInput(); //closing of ois also closes socket!
        //            try { ois.close(); } catch (IOException ioe) { /* ignore */ }
            return result;
        }//readObject()Why does ois.readObject() block? I get problems with this as the main while loop (above) calls readObject() as it's the only way to get server messages. But if i want to implement a synchronous call in adition to this asynchronous architecture (call listeners), the readObject() call of the synchronous method comes to late as readObject() call of the main loop got called before and therefore also gets the result of the (later) synchronous call.
    I tried fideling around with some state variables, but that's ugly and probably not thread safe. I'm looking for another solution to check messages from the server without reading data from the stream. is this possible?

    A quick fix:
    - Add a response code at the beginning of each message returned from the server indicating if the message is a synchronous response or a callback (asynch);
    - Read all messages returned from the server in one thread and copy callback messages in a calback message queue and the synch responses in an synch responses queue;
    - Modify your synchronous invocation to retrieve the response from the responses queue instead from the socket. Read the callback messages from the corresponding queue instead from the socket.
    Also take a look at my website. I'm implementing an upgraded version of this idea.
    Catalin Merfu
    High Performance Java Networking
    http://www.accendia.com

  • How to find the Web Dnpro component from the Source code ?

    Hi Gurus,
    Please help me to find out the WD Component Name from the Source Code?
    Regards
    Anil

    Hi Thomos,
    When i right clik on the screen i see the following line by line.
    -Back
    -forward
    -save background as
    -set as background
    -copy background
    -set as desktop item
    -select all
    -Paste
    -create shotcut
    -add to favorites
    -view source
    -encoding
    -print
    -refresh
    -export to microsoft excel
    -properties
    I have mentioned every thing i see when ever i right click on the screen.
    --Anil

  • How to get a Previously purchased app  from the App Store from a different account on the same computer?

    Recently had to replace my hard drive and some info has gone missing.  An App from the App Store for one.  How can I get it back now that I have a new account?  It wont let me sign on with the old one anymore.

    There's no need to create a new Apple ID just because the hard drive was replaced.
    Apps can only be re downloaded using the same Apple ID they were purchased with originally.
    You will have to re purchase the app using the new Apple ID.

  • How does one move a scanned document from the scanner to the SD card?

    I use a DELL laptop, plus the DELL All in One printer Model 922. I can scan something but then I would like to place it on my card for viewing on my TX.  I do scan it as a picture. Is there any other way? Is there another application I should be looking for?
    Post relates to: Palm TX
    This question was solved.
    View Solution.

    If you scan it as a picture, just HotSync it over using Palm Desktop and the Media button in the left side column.
    If your scanner can do "OCR" (Optical Character Recognition) you might be able to scan it as a Word document and then use Docs2Go to transfer it.
    I'd suggest upping the scan resolution a bit to give you the option of enlarging the image on your TX.  While viewing the picture, press the UP direction on the 5-way pad to Zoom In on the picture.
    WyreNut 
    Post relates to: Centro (AT&T)
    I am a Volunteer here, not employed by HP.
    You too can become an HP Expert! Details HERE!
    If my post has helped you, click the Kudos Thumbs up!
    If it solved your issue, Click the "Accept as Solution" button so others can benefit from the question you asked!

  • How to get ringtones on my iphone4 from the music on my phone

    I make the ringtones and have to email them to myself but still don't know how to get them on my phone to be able to use.

    In case you don't know, ringtones use a different format then songs.  When you say "I make the ringtones", you need to have used an appropriate utility to do that.
    Assuming you did, then place those ringtones into the "Tones" section on iTunes on your computer, and sync your iPhone using iTunes, making sure you have the right rule set up so your tones get synced.

  • How to get my usernames to appear from the drop down box then password automatically put in?

    =( ugh...
    I used to have my settings where it remembered my user name from the drop down box - so I would just type the first letter of my user name and a drop down box would appear and I could just click on my user name for that particular site and my password would automatically fill in...
    I changed something the other night and can't remember what the heck I did... now it won't remember ANY user name OR password or like on face book it has my user name and password there automatically when I open up the log in face book page.
    So I would like to know if anyone knows what needs to be clicked and unclicked to make it so:
    I start typing my user name and the drop down box appears with user names and then my password automatically fills.. I DO NOT want all my user names and passwords already IN the forms when I first open the website... but for me to actually type in a letter and then it fills it... like it used to =(
    /cry
    why do I touch stuff?
    Anyway I hope someone can help me because I am going nuts trying to figure it out and think I'm goofing things up even more =/
    I have firefix 3.6.10

    Does this help?
    * http://kb.mozillazine.org/Password_only_filled_after_entering_user_name
    * Make sure that you not run Firefox in (permanent) [[Private Browsing]] mode
    * You enter Private Browsing mode if you select: Tools > Options > Privacy > History: Firefox will: "Never Remember History"
    * To see all History and Cookie settings, choose: Tools > Options > Privacy, choose the setting <b>Firefox will: Use custom settings for history</b>
    * Uncheck: [ ] "Automatically start Firefox in a private browsing session"

  • How do I open a word document from a url?

    We have a document server and I need to open a MSWord document that is a template for LabView to populate (using bookmarks and Connectivity Toolkit).
    I have looked at the URL builder and I can't get that to work.  The Get Document does open the document but it doesn't seam to give the correct path to the Word Get Report so it doesn't give a good link.
    I can open it in the default browser which links to Word but again there isn't any link to feed to Word Get Report.
    Am I even close?
    Thank you,
    Ben
    Solved!
    Go to Solution.

    Here's a code snippet that should help you:
    It:
    initializes a HTTP session with a username and password,
    generates a random, non-existent filename with a doc extension
    Get's a file on URL to the temporary filename
    Closes the HTTP session
    Starts the Report Generaton Toolkit, with the file from the web as the template
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

Maybe you are looking for

  • Apple TV 3 has mirroring problem with Yosemite

    Just updated to Yosemite yesterday for my macbook pro retina 2013. At the same time, I bought an apple TV 3 for which I want to use my TV as an external monitor. Strangely, all iTunes movies streamed from my macbook work fine for the apple TV -- very

  • 501 5.1.3 Invalid address

    an internal application server relays mail mail via our 3 HTS.  In Application logs of the app server I notice this app servers fails to connec to mail servers.  I look at the 3 HT servers logs and on 2 of the HT server  Smtp receive Logs I notice th

  • Sudden slow performance Lenovo IdeaPad G4070 (59415695)

    Hello guys! I need help... My Lenovo IdeaPad G4070 (59415695) is suddenly on slow performance when in multitasking mode such as opening simultaneously NBA2k14, winamp, & adobe photoshop cs5. It performs or runs smoothly then afterwards it become on s

  • Can someone tell me which hard drive to get?

    I have a macbook pro 13 inch mid 2010. I want 1tb of internal hard drive space. which should I get. please leave the name or link. below

  • Repeating frame not visible when the query returns no rows

    I've developed a report whose output looks like this: Subinventory | Part Code |Part Description |Ordered Qty | Received Qty Mentone St | BATT | non serialised item | | Mentone St | SONY | spare parts MIN MAX | 30| 0 In the above report subinventory,