Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I`m making a sharepoint site analysis using windows form.

I already built a code get all sharepoint site information in target pc

But now, I want to make this.

1. Write a target site url in Text Box

2. Click start button.

3. Matched site data will save in database.

In this step, I don`t know how can I compare text box site url and sharepoint site url

I add my code, it just get all sites information.

Please help me how can I add or modify my code.

What I have tried:

C#
private static void bindWebApplication()
        {
            writeLog = new LogWrite();      
            
            var service = SPFarm.Local.Services.GetValue<SPWebService>(string.Empty);
            List<ListInfos> AllListInfo = new List<ListInfos>();

            //Web Application
            foreach(SPWebApplication webApplication in service.WebApplications)
            {
                string targetSiteURL = webApplication.AlternateUrls[0].Uri.OriginalString;
                try
                {
                    //Content Database
                    foreach(SPContentDatabase contentDatabase in webApplication.ContentDatabases)
                    {
                        //Site Collections
                        foreach(SPSite site in webApplication.Sites)
                        {
                            //Sites
                            foreach(SPWeb web in site.AllWebs)
                            {
                                //Lists
                                foreach(SPList list in web.Lists)
                                {
                                    if (!list.Hidden && list.BaseTemplate != SPListTemplateType.DataSources && web.WebTemplate != "SRCHCEN" && !string.IsNullOrEmpty(list.DefaultViewUrl)) ;
                                    {
                                        string listTitle = GetListName(list);

                                        if(
                                            (
                                                //do something
                                            )
                                            &&
                                            (
                                                //do something                                            
                                            )
                                          )
                                        {
                                            ListInfos listinfos = new ListInfos();

                                            ListInfo listinfo = new ListInfo();
                                            listinfo.GetListInfo(list, ref listinfos);

                                            WebInfos webinfo = new WebInfos();
                                            webinfo.GetWebInfos(web, ref listinfos);

                                            SiteInfos siteinfo = new SiteInfos();
                                            siteinfo.GetSiteCollectionInfo(site, ref listinfos);

                                            ContentDBInfo contentDBInfo = new ContentDBInfo();
                                            contentDBInfo.GetContentDBInfo(contentDatabase, ref listinfos);

                                            ApplicationInfo appInfo = new ApplicationInfo();
                                            appInfo.GetApplicationInfo(webApplication, ref listinfos);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch(Exception ex)
                {
                    writeLog.LogsWrite(ex.ToString());
                }
            }
        }
Posted
Updated 13-Oct-16 23:14pm
v3

1 solution

i solved it myself...

I add a code like this. underline marked line.

C#
private void insertWebApplicationInfo()
        {
            writeLog = new LogWrite();
            string txturl = mtextUrl.Text;
           
            var service = SPFarm.Local.Services.GetValue<SPWebService>(string.Empty);
            List<ListInfos> AllListInfo = new List<ListInfos>();

            //Web Application
            foreach(SPWebApplication webApplication in service.WebApplications)
            {
                string targetSiteURL = webApplication.AlternateUrls[0].Uri.OriginalString;

                if (txturl != null && targetSiteURL != null)
                {
                    if (txturl == targetSiteURL)
                    {
                        try
                        {
                            //Content Database
                            foreach (SPContentDatabase contentDatabase in webApplication.ContentDatabases)
                            {


Add this line
1. get text box value
C#
string txturl = mtextUrl.Text;


2. get web application url
C#
string targetSiteURL = webApplication.AlternateUrls[0].Uri.OriginalString;


3. Add if
C#
if (txturl != null &amp;&amp; targetSiteURL != null)
                {
                    if (txturl == targetSiteURL)
                    {
                        try
 
Share this answer
 
v4

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