How to exclude sub sites in navigation from C# code

                                                            
Hi,
I need show Global navigation items in custom web part, below code is returning global navigations with sub sites. 
how to exclude sub sites and return only global navigation items links?
using (SPSite spsite = new SPSite(SPContext.Current.Web.Url))
                    using (SPWeb web = spsite.OpenWeb())
                        SPNavigationNodeCollection colletion = web.Navigation.TopNavigationBar;
                        foreach (SPNavigationNode navigationNode in colletion)
//Getting all global navigation nodes including sub sites
please help me to resolve this.
Thanks.

This should work
if(!web.isRootWeb){web.Navigation.GlobalNavigationNodes.Delete(navigationNode);web.Update()}
Refer to the following post for more information
http://www.learningsharepoint.com/2010/09/28/add-links-to-top-navigation-sharepoint-2010-programmatically/
--Cheers

Similar Messages

  • How to make sub sites in SharePoint 2010 as Read Only

    Hello,
    We have a requirement to make sub site as read only in SharePoint 2010 programmatically.
    How we can achieve it using Server Object Model ?
    Thanks,
    Hatim

    Hi,
    You can write a WinForm program, and use
    SPSecurableObject.BreakRoleInheritance method to achieve your requirement.
    More information for your reference:
    http://fangdahai.blogspot.com/2012/09/how-to-set-sub-site-in-read-only-mode.html
    https://social.msdn.microsoft.com/Forums/en-US/1f836da6-88ea-4d88-9e43-3383d139ca01/what-is-the-idea-of-stop-inheriting-permission-from-parent-site?forum=sharepointdevelopment
    Best Regards
    Dennis Guo
    TechNet Community Support

  • How to exclude a set of materials from  cycle counting physical inventory

    How to exclude a set of materials from  cycle counting physical inventory
    Details:
    Set of material to be uploaded to SAP on say Jan-2011  from another system with cc indicator D:once
    in a year  and fixed,before uploading into SAP physical inventory will be done .
    So we donot want again those materials to fall in the cycle counting in the same year.
    So is there a method to exclude these materials from CC counting for the year 2011
    or is there some way to upload last inventory count date in SAP system so that it will exclude those
    materials?
    Any answers will be appreciated.
    Thanks
    Bijay

    HI Antony
    Thank you for your reply.
    If material count is less than this method is well valid.
    IN our case there are 7lakhs materials and having diff cc indicator A,B,C,D...
    So it will cumbersome for client to keep track of all those materials when to update cc indicator.
    So any other thought? can we upload last count date while updating materials details  or similar
    Thanks
    Bijay

  • How do I migrate sites and settings from CS6 to CC?

    How do I migrate sites and settings from CS6 to CC?
    Now goddam way I am going to rebuild 13 websites just to use CC

    Well. With Dreamweaver CC, you could use the Sync settings feature to transfer workspaces from one CC machine to the other.
    But with CS6 workspaces being transferred to CC there is a not so intuitive way to do it.
    Backup/Rename the CC workspace folder [resent at C:\Program Files (x86)\Adobe\Adobe Dreamweaver CC\configuration\workspace to anything you like.
    Copy the workspace folder from C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS6\configuration\workspace to C:\Program Files (x86)\Adobe\Adobe Dreamweaver CC\configuration\workspace
    Now you should have your CS6 workspaces in CC.

  • How to execute a Command Prompt command from J2SE code executing on Windows

    How to execute a Command Prompt command from J2SE code executing on Windows??
    Please help me

    [http://java.sun.com/docs/books/tutorial/getStarted/]
    ~

  • How to send SMS ( Short Message Service ) from java code

    Hi
    How to send SMS ( Short Message Service ) from java code.
    Thanks
    Gaurav

    Do you need to receive SMS? If you need to receive SMS, you will need to host your own GSM device or modem so that people can send you SMS.
    If not, you can just use internet SMS gateways like clickatell as mentioned above will do the work, and post to them by HTTP, XML or email. The cost is about 6-8 cents per SMS. There are cheaper services, but not always reliable. If you need to host your own GSM device, you can use software like http://www.kannel.org (GPL Open Source) or http://www.visualgsm.com. Alternatively, you may obtain a shortcode from your Telco - but these come with monthly subscription of maybe one or two hundreds.
    Regards,
    Joshua
    <SMS Gateway>@Expert

  • If i deleted my history, is there a way you can still tell me how many times a site was visited from my MacBook?

    My history has been wiped out. I would like to know if there is a way i can see how many times a site was previously visited using my MacBook. Pelase advise. Thansk!

    no, i deleted the addresses from my history but was able to pull them up from the cookies. i want to know if i can view how many times the site was viewed ever after it has been deleted out of my history..
    thanks!

  • How to exclude the PO matched invoices from entering the Approval Heirarchy

    Hi,
    How do you exclude the PO matched invoices from entering the Approval heirarchy?
    I refered to the note [ID 337714.1], wherein it states that the "In the workflow definition file - apfiawie.wft - the attribute EXCLUDE_PO_MATCHED is to be set to 'Y'".
    When I open the file in the workflow builder, I am not able to modify the attribute as mentioned in the note.
    Can anyone please give a solution to this problem as all the invoices are getting in the approval workflow.
    Thanks & Regards,
    Atul

    Dear All,
    If anybody face the same issue pls give us solution.
    Thanks,
    Atul

  • How to exclude Table`s  scroll bar from Drag Source

    Hi
    i have an af:table inside other af:table as its column like below sample
    and user can drag inner table and drop it to other row of outer table but when user click on the scrollbar of inner table to scrolling the inner table selected as drag source and user con not scroll inner table
    so is it possible to exclude scroll bars of table from drag source?
    depart Id
    Dep name
    Emp
    dep1
    IT
    emp Name
    emp email
    emp Tel
    jan
    [email protected]
    8990
    dav
    [email protected]
    8844
    dep2
    Finance
    emp Name
    emp email
    emp Tel
    smit
    [email protected]
    8745
    mary
    [email protected]
    8952

    Hi,
    Always mention your JDev version.
    As Timo mentioned, it would be easier for you if you use a treeTable. Any specific reasons why you don't want to use it? If you want to do it through iterator, you could also use a grid layout (depends on your JDev version) to make it look like a grid.
    -Arun

  • How to modify an existing xml file from java code.

    Hi
    I have worked on creating a new xml file from java code using xmlbeans.But if i try to modify an already existing file using java code I am unable to get errorfree xmlfile.
    For example if xml file(studlist.xml) is as below:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    Now suppose i have set name to victor using student.setName,
    and set age to 20 using setAge from javacode,
    the new xml file is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    <Student>
              <Name>victor</Name>
              <Age>20</Age>
         </Student>
    As observed this is not a valid xml file.But how can i modify without any errors?

    I know it's an old post, but I found this while doing a google search for something else, and don't like to leave it un-aswered
    Just in case anyone has a similar problem... In this case the new elements have been appended outside of the root element
    What you need to do is first get the root element and then append the new children to that, there are several ways of getting the root element, which depend on what you want to do with the elements you get back here's a simple (incomplete) way.
    // gets the root element of the specified file (code not shown)
    Element rootElement= new SAXReader().read(file).getRootElement();Then just append the new elements as below (this is non-generic code and would need to be modified for your situation)
    // write a new student element
    Element student = document.createElement("Student");  // creates the new student
    rootElement.appendChild(student); // ***appends it to the root element***
    Element name = document.createElement("Name"); // creates the name element
    name.appendChild(document.createTextNode("Fred")); // adds the name text to the name element
    student.appendChild(name); // appends the name to the student
    Element age= document.createElement("Age"); // creates the age element
    age.appendChild(document.createTextNode("26")); // adds the age text to the age element
    student.appendChild(age); // appends the name to the studentThen flush ya buffers or whatever and write the file
    Edited by: Dream-Scourge on Apr 23, 2008 11:10 AM

  • How to access an object's variable from native code

    i am passing an object in a native method.i have to change the value of the object's variable.how do i access the variable of object and assign it new value from c++ code.when i try to access it i get a message that the variable must have a class/sruct/union type.
    pl. help.

    I'll tell You if You send me the structure of this object in Java. And a name of field what are You thinking about.
    Maciek

  • How to click a HTML page button from Java code?

    Know the HTML page name and the button id in this page, how to click the button automaticly in java code(Like in awt or swing)?

    ukkus wrote:
    Hi,
    Thank for the quick reply,
    It will be very helpful if you can tell me how can we do this, I am not able to get how to do the same, with the link that you have provided.You haven't even had time to read it yet.
    >
    Actually main scenario is:
    I have to RUN a JSP report which will call this script. That JSP report and script is in UNIX server. Can you please explain how to perform this task.Running this from a JSP is an even worse programming practice than running it from a standalone application.

  • How am i supposed to prevent sm from pasting code in my JSP page?

    Hello,
    as i was testing my JSP page i noticed that when sm places code in an input box , it seems that the page is affected by that.
    Well i have a very simple form like:
    <form  style="text-align:left" method="POST" name="edit" action="Edit" >
    <input type="text" name="year" size="5" maxlength ="50" value="<%= convertdate.ReturnYear((resultset.getString(19)) %>">
    <input type="submit" name="Submit" value="Store Data" >
    </form>i noticed that when i was placing code in the button year of the form like:
    out.println("<HTML><HEAD><TITLE> " + "Error in PAGE BLAH BLAH BLAH" + " </TITLE></HEAD><BODY>");my website was affected by that and some pages looked different and couldn't display data from the database, although the data existed in the db.
    What am i supposed to do? How am i supposed to prevent a user from inserting code in inputs of a form?
    Also, sometimes when i was pasting code, some SQL exceptions appeared saying : Data too long for field etc.
    The weird was that the data was in the limit. I'm very worried about this problem because the sql exceptions show the names of my tables and i think
    that this is dangerous for malicious attacks in the website.
    Thanks, in advance!
    Edited by: g_p_java on Sep 5, 2009 5:09 PM
    Edited by: g_p_java on Sep 5, 2009 5:14 PM
    Edited by: g_p_java on Sep 5, 2009 5:15 PM

    smogura.eu wrote:
    All notices are important & how to say... you can place Java code in JSP, but in commercial job you will need to find new job.
    Well i'm not actually working somewhere, i'm student and i have to make this project.
    It's the first time I use JSP, servlets etc, so that's why i find a difficulty in using them.
    Why your pages are messed? If you put HTML code in db, rendered page is like
    ..="50" value="<HTML><HEAD...{code}
    this will prevent browser to render page properly. Well i was actually pasting some data in order to check if the data is too long for the field and afterwards the page changed and many fields disappeared...
    There are two ways to prevent inserting code, in your JSP, and you need use it, as no separating view logic, data acquisition from page will not prevent this error
    1. You need disallow user entering ", <, ' etc...., best way by validating input on server side, by this will prevent user from entering all texts, or
    2. You need replace all HTML special char with their HTML codes when rendering, the simplest way
    convertdate.ReturnYear((resultset.getString(19)).replace("\"", "&#34'").replace(...).replace(...)
    {code}
    You must use this in back logic.May you please elaborate on that, you mention that i shall replace the year with "&#34'",
    What is that "&#34'"?
    and why do you use 3 "replaces"?
    About prepared statements.
    Preparation will not only prevent you from SQL injections, but can speed up application, if your driver uses statement caching.
    Why after creating prepared statement, you then create normal statement, in your example code?I hadn't noticed that, thanks.I 'll change them. But Statement is less secure than PrepareStatement?
    Thanks, in advance!

  • FB60, How to exclude a G/L account from being selected ?

    This is a continuation of a previous thread that was closed by accident!!
    The original question hasnu2019t been answered yet.
    Question
    =======
    I am in need to EXCLUDE a specific G/L account from being selected, from the drop down list, when executing FB60 (Enter Vendor Invoice) to create a new vendor invoice ?
    1) Is this doable ?
    2) Could this be done programmatically (ABAP team) ?
    3) Could this be done at Security Role level (Basis & Security ABAP team)  by using the field BRGRU of the F_BKPF_BES Authorization Object ?
    I have received so far very useful remarks from Paul01, Mauri, SAPFICO, Mohammed Zia, and Sudhaker Gogula.
    THANK YOU ALL!
    Here are my answers to each one:
    To Mauri:
    ========
    YES, we define the authorization Group via FS00 --> Control data, which means the relevant authorization object will be F_BKPF_BES.
    As I said earlier, the corresponding field will be BRGRU and and not BEGRU.
    Then the question is, WHICIH AUTHORIZATION GROUP DO I SET, for the value of BRGRU, there are thousands !!
    To Mohammed
    ============
    How do I "block that GL account for postings in GL master record" ??
    Programmatically (ABAP) or via Security Role(s) ?
    To Sudhaker
    =========
    Could you please elaborate the solution USE VALIDATION.
    I am not familiar with that!
    Is it something that ABAPers do ?
    Could something be done by using Authorization Groups // Authorization Objects ?
    Thank you all, in advance for your comments/ideas/solutions!
    Best regards,
    Tom

    Dear Tom,
    if You insert an authorization Group into FS00 then You should create a role by transaction PFCG to link to Your user.
    Then You have to link to this role the transactions You want the user to use and into the Authorization TAB, You have to insert the relevant intervals of Authorization group, excluding the one to which the user cannot post to:
    Changed    Accounting Document: Account Authorization for G/L Accounts
    Maintained Accounting Document: Account Authorization for G/L Accounts
       Activity                       Create or generate
       Authorization Group            HERE!!!!!!
    Then You have to save and to generate.
    Anyway the easier way, in my opinion, is to build up a validation by OB28 at line item (call up point 2) and define an error
    message in case the use should use the G/L Account in question.
    example:
    Prerequisite
    BKPF-BUKRS = 'MAO1' AND SYST-TCODE = 'FB60'
    Check
    BSEG-HKONT = '160000'
    Message
    Message type   E         Message class     Z1
    Message number  032
    Message text    Please don't use the G/L account 160000
    I hope this can help You.
    Mauri

  • How extract a custom site-collection templates from Central Administration (SharePoint 2007)

    In our company installed SharePoint 2007. On the tab "Create site collection" in the Central Administration we have a custom template (for russian language), which has been installed by previous developer. There is no documentation or installation
    file about this template. 
    Please suggest how i can extract this template (installation file) from Database? We make a migration to a new server and i need install this one more...

    we need to extract using visual studio
    Once you have the .stp file, you can change the .stp file extension to .cab file
    http://sharepoint.stackexchange.com/questions/53095/visual-studio-project-template-to-extract-sharepoint-list
    http://www.pearsonhighered.com/samplechapter/0321336615.pdf

Maybe you are looking for

  • I requested for my iPhone 4 to be unlocked nearly 3 weeks ago and I still haven't recieved a confirmation email to say it has been successful

    My boyfriend upgraded to an iPhone 5 recently and decided to give me his old iPhone 4, but i'm on Vodafone and his iPhone is locked to Orange. So he rang up Orange to request an unlock which cost £20 and the guy said it could take upto 28days (which

  • New iPhone 4 not working

    Hi. I have very upset situation here. I'm from Russia, i was in Spain so i bought simfree iPhone 4. When i got back i opened iphone 4. turned it on, connected it to iTunes on my mac, then screen goes black and nothing appeared on the screen then it s

  • Open Hub - Header in flat file

    Hi there Experts. I am working with a opeb Hub destination, and so far everything has been straight forward. But i need to include headers in the first line of the file. By default the Open Hub i generating a Control File, so it is possible to look i

  • Difference in read/write between Windows Vs Linux

    Hi, Can you please write, whether it is a bug or my ignorance. I thought, if a java program runs in Windows then it will run in other platform too, without editing any code. It proved me wrong. So is it a bug? Ref: Fedora linux version 5 Kernel ver.

  • PS2013: convert Idea to Project

    Hi, does anybody have any clue about what permissions a user need in order to be able to convert an Idea in a Sharepoint List to a project in PS2013? It works with an Admin, but not with a user configured as a PM. Thanks, Fabrizio.