Merging and grouping libraries code problem - sharepoint-2010

I'm writing C# code to merge multiple libraries within a site collection and applying grouping on them. But grouping doesn't include documents from other sites regardless all share same meta data. Below, Blue box docs are from one site and green box docs are from other site and they don't group together.
Here are my code ,
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc;
SPSite curSite = SPContext.Current.Site;
SPWebCollection subSites = curSite.AllWebs;
dc = new DataColumn("Title", Type.GetType("System.String"));
dt.Columns.Add(dc);
dc = new DataColumn("ReferenceNo", Type.GetType("System.String"));
dt.Columns.Add(dc);
dc = new DataColumn("Domain", Type.GetType("System.String"));
dt.Columns.Add(dc);
dc = new DataColumn("Created", Type.GetType("System.DateTime"));
dt.Columns.Add(dc);
for (int i = 0; i < subSites.Count; i++)
{
SPListCollection lists = subSites[i].Lists;
foreach (SPList list in lists)
{
if (list.Title == "Published Documents")
{
SPQuery myquery = new SPQuery();
//myquery.Query = "<GroupBy><FieldRef Name='Domain' /></GroupBy><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy>";
myquery.Query = "<GroupBy><FieldRef Name='Domain' /></GroupBy>";
SPListItemCollection items = list.GetItems(myquery);
foreach (SPListItem item in items)
{
if (item != null)
{
dr = dt.NewRow();
dr["Title"] = item["Title"];
dr["ReferenceNo"] = item["ReferenceNo"];
dr["Domain"] = item["Domain"];
dr["Created"] = item["Created"];
dt.Rows.Add(dr);
}
}
}
}
}
//dt.DefaultView.Sort = "Created DESC";
spGridView.AllowGrouping = true;
spGridView.AllowGroupCollapse = true;
spGridView.GroupField = "Domain";
spGridView.DataSource = dt;
spGridView.DataBind();
Updates:: , Sorting Data Table with Domain fixed the issue..
**dt.DefaultView.Sort = "Domain";**

Rishi's answer:
Sorting Data Table with Domain fixed the issue..
dt.DefaultView.Sort = "Domain";
naveed's comment:
Perfect it worked for me. all goes well just we need to have
dt.DefaultView.Sort = "Your Sorting Attribute";

Related

RDLC Design, A column of Row number showing extra value

My rdlc report is working fine. but displaying 0 that i need to remove. please help. attached screenshot describe the design problem.enter image description here
C# code
protected void GenerateReport()
{
if (Request.QueryString["rdlcrepname"] != null)
{
reportName = Request.QueryString["rdlcrepname"].ToString();
string strprm1 = Request.QueryString["prm1"].ToString();
var strprm2 = Request.QueryString["param2"] != null ? Convert.ToInt32(Request.QueryString["param1"].ToString()) : 0 ;
SqlParameter[] clsParam = new SqlParameter[2];
clsParam[0] = new SqlParameter("#param1", strprm1);
clsParam[1] = new SqlParameter("#param2", strprm2);
ds = dataAccess.GetDataSet("spname", clsParam);
dsShow.Tables.Add();
dsShow.Tables.Add("FinalDisplayDataHeader");
dsShow.Tables.Add("FinalDisplayData");
//DataColumns-Header SQL of Header
dsShow.Tables["FinalDisplayDataHeader"].Columns.Add("col1", typeof(string));
dsShow.Tables["FinalDisplayDataHeader"].Columns.Add("col2", typeof(string));
dsShow.Tables["FinalDisplayDataHeader"].Columns.Add("col3", typeof(string));
dsShow.Tables["FinalDisplayDataHeader"].Columns.Add("col4", typeof(string));
//DataColumns SQL of data
dsShow.Tables["FinalDisplayData"].Columns.Add("col1", typeof(string));
dsShow.Tables["FinalDisplayData"].Columns.Add("col2", typeof(string));
dsShow.Tables["FinalDisplayData"].Columns.Add("col3", typeof(string));
if (ds.Tables["Table"].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables["Table"].Rows.Count; i++)
{
dsQPUDisplay.Tables["FinalDisplayDataHeader"].Rows.Add(); //Header
dsShow.Tables["FinalDisplayDataHeader"].Rows[i]["col1"] = ds.Tables["Table"].Rows[i]["col1"].ToString();
dsShow.Tables["FinalDisplayDataHeader"].Rows[i]["col2"] = ds.Tables["Table"].Rows[i]["col2"].ToString();
dsShow.Tables["FinalDisplayDataHeader"].Rows[i]["col3"] = ds.Tables["Table"].Rows[i]["col3"].ToString();
dsQPUDisplay.Tables["FinalDisplayDataHeader"].Rows[i]["col4"] = ds.Tables["Table"].Rows[i]["col4"].ToString();
for (int k = 0; k < 4; k++)
{
dsShow.Tables["FinalDisplayData"].Rows.Add(); //Data
dsShow.Tables["FinalDisplayData"].Rows[k]["col1"] = ds.Tables["Table1"].Rows[k]["col1"].ToString();
dsShow.Tables["FinalDisplayData"].Rows[k]["col2"] = ds.Tables["Table1"].Rows[k]["col2"].ToString();//This is right
dsShow.Tables["FinalDisplayData"].Rows[k]["col3"] = ds.Tables["Table1"].Rows[k]["col3"].ToString();
}
}
reportPath = string.Empty;
rdlcReportViewer.LocalReport.ReportPath = GetReportPath(reportName);
//rdlcReportViewer.LocalReport.DataSources.Clear();
ReportDataSource rdsHeader = new ReportDataSource("DataHeader", dsShow.Tables["FinalDisplayDataHeader"]);
ReportDataSource rdsData = new ReportDataSource("Data", dsShow.Tables["FinalDisplayData"]);
rdlcReportViewer.LocalReport.DataSources.Add(rdsQPUheader);
rdlcReportViewer.LocalReport.DataSources.Add(rdsQPUData);
}// for complete batch students loop closed
rdlcReportViewer.DataBind();
rdlcReportViewer.LocalReport.Refresh();
}
}
RDLC is in design. code above give you idea how i am generating the rdlc report. enter image description here this link describe issue of RowNumber display
My issue got resolved by enabling regional formatting option of the particular textbox. Click on the link to view image

Control data come from sql

I have a dropdownlist and it takes names of neighborhood from sql.
I want to show neighborhood's features on screen.
If I choose a neighborhood has been processed before now, It's no problem. My code can show features of its neighborhood.
But if I choose a new neighborhood (nobody adds information about that neighborhood before). There are no different thing on the screen.
I want to show on dropdownlist "New" as text. I defined 'else' status in my code.
How can I solve this problem?
That is my code :
string DurumTespiti = "";
string mahalle = ""; //mahalle means “neighborhood”
ddlMahalle.Visible = true; // it is a dropdownlist
SqlConnection baglanti = new SqlConnection("Data Source = WEBPMT\\ARCSQL;UID=sa;PWD=PMT*1881;DATABASE=ProjeTakip;");
SqlCommand komut = new SqlCommand();
baglanti.Open();
komut.Connection = baglanti;
komut.CommandText = "select * from ProjeTablo";
komut.ExecuteNonQuery();
SqlDataReader dr = komut.ExecuteReader();
while (dr.Read())
{
mahalle = "";
mahalle = dr["mahalle"].ToString();
if (mahalle == ddlMahalle.SelectedValue) // Compare value of dropdownlist and name of neighborhood in sql.
{
Label9.Text = "Mahalle doğru seçildi!";
}
mahalle = "";
}
else
{ // if value of dropdown list couldn’t be find in sql
Label9.Text = "Böyle bir mahalle yok";
}
mahalle = "";
}
dr.Close();
baglanti.Close();

Rally c# task time spent

I have a C# .net application using the rally 3.0.1 API. When I query task in my system I get 0.0 for time spent when I know they have time against them. Anyone know how to get this? Below is my code:
if (uTasks.Count > 0)
{
Request taskRequest = new Request(resultChild["Tasks"]);
QueryResult TaskQueryResult = restApi.Query(taskRequest);
foreach (var items in TaskQueryResult.Results)
//foreach (var items in uTasks)
{
DataRow dtrow2;
dtrow2 = dt.NewRow();
dtrow2["TaskID"]=items["FormattedID"];
dtrow2["Task Name"] = items["Name"];
if (items["Owner"] != null)
{
var owner = items["Owner"];
String ownerref = owner["_ref"];
var ownerFetch = restApi.GetByReference(ownerref, "Name");
string strTemp = ownerFetch["_refObjectName"];
dtrow2["Owner"] = strTemp.Replace(",", " ");
}
\\else { dtrow2["Owner"] = ""; }
dtrow2["Task-Est"] = items["Estimate"];
dtrow2["Task-ToDo"] = items["ToDo"];
dtrow2["Task-Spent"] = items["TimeSpent"];
dtrow2["ObjectType"] = "T";
dt.Rows.Add(dtrow2);
}
}
It seems like that should work. You may want to make sure you're including the TimeSpent field in your fetch before issuing the request.
taskRequest.Fetch = new List<string>() { "TimeSpent" };

Lucene 30 fuzzy search

I user LUCENE_30 for my search engine but i cannot make fuzzy search.How can i make it work?
I tried use GetFuzzyQuery but nothing happens.As i see is not supported.
Here my code :
if (searchQuery.Length < 3)
{
throw new ArgumentException("none");
}
FSDirectory dir = FSDirectory.Open(new DirectoryInfo(_indexFileLocation));
var searcher = new IndexSearcher(dir, true);
var analyzer = new RussianAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
var query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_30, searchQuery, new[] {"Title" }, new[] { Occur.SHOULD }, analyzer);
var hits = searcher.Search(query, 11110);
var dto = new PerformSearchResultDto();
dto.SearchResults = new List<SearchResult>();
dto.Total = hits.TotalHits;
for (int i = pagesize * page; i < hits.TotalHits && i < pagesize * page + pagesize; i++)
{
// Document doc = hits.Doc(i);
int docId = hits.ScoreDocs[i].Doc;
var doc = searcher.Doc(docId);
var result = new SearchResult();
result.Title = doc.Get("Title");
result.Type = doc.Get("Type");
result.Href = doc.Get("Href");
result.LastModified = doc.Get("LastModified");
result.Site = doc.Get("Site");
result.City = doc.Get("City");
//result.Region = doc.Get("Region");
result.Content = doc.Get("Content");
result.NoIndex = Convert.ToBoolean(doc.Get("NoIndex"));
dto.SearchResults.Add(result);
}
Fuzzy queries certainly are supported. See the FuzzyQuery class.
The query parser also supports fuzzy queries, simply with a tilde appended: misspeled~

Iterate through collection of List<object>

I have what is probably simple problem, but I am stumped. I call a method from another assembly that returns me a List<object>, this data is Excel spreadsheet data queried using LinqToExcel. Under the scenes, that collection is actually a List<LinqToExcel.Cell>. In LinqToExcel, that makes up a LinqToExcel.Row. I want to be able to bind this data to a Telerik ASP.NET MVC grid for viewing. Here's my controller code:
TypeOfServiceCodeListingDetailViewModel model = new TypeOfServiceCodeListingDetailViewModel();
model.Excel_Data = new List<LinqToExcel.Row>();
using (LinqToExcelReader reader = new LinqToExcelReader(fileName, true))
{
previewData = reader.ReadRawDataByPage(5, 0);
foreach (LinqToExcel.Row item in previewData)
{
model.Excel_Data.Add(item);
}
return View(new GridModel(model.Excel_Data));
}
And in my view:
#(Html.Telerik().Grid(Model.Excel_Data)
.Name("Grid2")
.HtmlAttributes(new { style = "width:400px;" })
.DataBinding(dataBinding => dataBinding.Ajax().Select("GetExcelData", "TypeOfService"))
.Columns(columns =>
{
columns.AutoGenerate(column =>
{
column.Width = "150px";
});
}))
Here's what my grid has headers like the below with no data:
Capacity Count
Thanks for the help!
Here's the code that solved my problem. I'm sure there's a better approach.
using (LinqToExcelReader reader = new LinqToExcelReader(modelDetail.FileName, true))
{
var previewData = reader.ReadRawDataByPage(5, 0);
List<List<string>> masterList = new List<List<string>>();
for (int x = 0; x < previewData.Count; x++)
{
List<string> list = new List<string>();
foreach (var cell in (LinqToExcel.Row)previewData[x])
{
list.Add(cell);
}
masterList.Add(list);
}
var listTest = masterList;
modelDetail.ExcelData = new List<ExcelData>();
foreach (List<string> theList in masterList)
{
ExcelData xlsData = new ExcelData();
xlsData.Column1 = theList[0];
xlsData.Column2 = theList[1];
xlsData.Column3 = theList[2];
xlsData.Column4 = theList[3];
xlsData.Column5 = theList[4];
xlsData.Column6 = theList[5];
xlsData.Column7 = theList[6];
xlsData.Column8 = theList[7];
xlsData.Column9 = theList[8];
xlsData.Column10 = theList[9];
modelDetail.ExcelData.Add(xlsData);
}