|
This is one of those places where the documentation can be invaluable. The answer to your question lies in the Enumerable.AsEnumerable(TSource) Method documentation in the remarks area.
...the AsEnumerable<TSource> method can be used to hide the custom methods and instead make the standard query operators available.
So, in your snippet the coder wants to make sure that the IEnumerable.Select method is called rather than any other method named "Select" on the object. This is generally to provide compile-time safety to code where ambiguities might crop up. You see this sort of sanity check a lot in code that will accept dynamics or generics.
As to your second question: always use ToArray() for immutable collections. It has less overhead and is generally more efficient if you're providing collections that won't be modified (add or remove items) later within your application.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
I am attempting to download a csv file from Azure container blob, read and load it to a dataset and then bind it to the radgrid.
I can download the data and set it to a string (the sample data is listed below) but not sure how to load it to the dataset.
When I load the data to a stream and then try to load it to a dataset, I received the following error: "Data at the root level is invalid. Line 1, position 1."
Here is a sample of the Data that is in the file ( I also tried it with no hdr record, same results...)
DeptCode,DeptName,AccountCode,Description,Qty,Expense
1001,Presidents,6220,FT Senior Administrator,1,126000
1001,Presidents,6221,FT Professional Staff,1,105050
1001,Presidents,6300,FT Administrative,1,60000
1001,Presidents,6425,FT Technical/Paraprofessional,1,70000
1001,Presidents,6426,PT Technical/Paraprofessional,1,32000
Here is my source code....
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("hsc2");
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference(FileUpload1.FileName);
//...Create or overwrite the "myblob" blob with contents from a local file.
using (var memoryStream = new MemoryStream())
{
blockBlob.DownloadToStream(memoryStream);
memoryStream.Position = 0;
StreamReader streamReader = new StreamReader(memoryStream);
//String blobText = streamReader.ReadToEnd();
DataSet ds1 = new DataSet();
ds1.ReadXml(streamReader);
RadGrid1.DataSource = ds1;
RadGrid1.DataBind();
RadGrid1.Rebind();
}
|
|
|
|
|
How to add a Nuget Package Using dotnet add
|
|
|
|
|
|
I am trying to open a csv file and do some formatting.
****
Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
Dim myexcel As New Excel.Application
Dim myworkbook As Excel.Workbook
Dim foldername As String
foldername = "C:\SplitFiles\"
Dim path1 As String
Dim path2 As String()
If Directory.Exists(foldername) Then path2 = Directory.GetFiles(foldername)
For Each path1 In path2
If File.Exists(path1) Then
MsgBox(path1)
myworkbook = myexcel.Workbooks.Open(path1, Format:=6, Delimiter:=",", Editable:=True)
myworkbook.Activate()
End If
Next path1
End Sub
End Class
the csv file does not open..
|
|
|
|
|
What error you are getting?
modified 20-Sep-20 21:01pm.
|
|
|
|
|
I dont get an error.
Just that when the workbook.open(path1) is executed. it wouldn't open the file. I have to open the file and make it active workbook and active sheet and have to do some formatting on the worksheet. then save and close.
the directory has around 40 files which will have similar formatting to be done.
thanks
Kumar
|
|
|
|
|
You've posted this in the ASP.NET forum. Office Interop doesn't work in ASP.NET; neither does MsgBox .
They might appear to work when you're debugging the code in Visual Studio. But that's only because the client and server are the same computer in that instance.
As soon as you deploy your code to a real server, the MsgBox call will either crash, or cause your code to hang waiting for someone to log in to the server and dismiss the hundreds of hidden message boxes, and then close the hundreds of hidden instances of Excel.
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you want to open a file on the client, then you need to write it to the response. And to pre-empt your next question: no, you can't force the user to open it, or to save it to a specific location.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi. I am currently working on product where I need to host couple of videos which are paid contents. I have no exact idea what could be best approach to do this. Where can we host these contents and provide access to paid users? Do we need seperate video hosting or this can be hosted on IIS folders itself?
Does anyone have any good suggestion? Appreciate any help, thank you.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Hi ,
I am trying to build dashboard with .net but it not working out.
Can i have ant=y steps or code to make it with the help of bootstrap .
|
|
|
|
|
What's not working out? Are you facing any issue?
modified 20-Sep-20 21:01pm.
|
|
|
|
|
What are the aspects every ASP.Net developer must know ?
|
|
|
|
|
In what context your question is?
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Basic Development concept of ASP.NET.
|
|
|
|
|
Hi,
I have received an ASP.Net MVC application from a colleague that I have to start working on, it had different dll reference errors when it was given, at that time it was showing me errors in the errors list, after adding the dlls when I compiled the Orange sign on the dlls is gone but when I compile the application it says build failed as below:
Rebuild All: 3 succeeded, 1 failed, 0 skipped
But its not giving me any details about the error in the error window. I could able to build all other assemblies individually by unloading the UI application, then added UI application still it gives me failed and doesn't display the details of the error in the error Window.
Here are the Warnings I am getting, any help would be very helpful - thanks in advance friends.
Warning 3 Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="log4net" culture="neutral" publicKeyToken="669e0ddf0bb1aa2a" /><bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0" /></dependentAssembly></assemblyBinding> XXXXX.SUD.CRS.Services (XXXXX.SUD.CRS.Services\XXXXX.SUD.CRS.Services)
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
-- modified 9-Feb-18 13:02pm.
|
|
|
|
|
Hi, we do a lot with asp.net pages accessing our sql servers and using gridviews which works out good for a bringing back lists and even have images incorporated in those views but looking for way to show more like a lot of shopping sites where might have multiple boxes going across with maybe item desc, price, image, add to cart button and maybe more details. So might have like 4-6 boxes across then multiple rows. Hoping to be able to make dynamic based on sql data. Don't think gridviews will work but looking for any suggestions or examples. We do mostly vb.net so that would help for example. Thanks.
|
|
|
|
|
|
i am working with 4 fields but i may have to search 100 fields. so to mention 100 fields name in where is very cumbersome.
please suggest best approach when we search a value against all fields or few specific fields.
if (!String.IsNullOrEmpty(SearchText))
{
customer = customer.Where(s => s.CompanyName.ToUpper().Contains(SearchText.ToUpper())
|| s.ContactName.ToUpper().Contains(SearchText.ToUpper())
|| s.ContactTitle.ToUpper().Contains(SearchText.ToUpper())
|| s.Address.ToUpper().Contains(SearchText.ToUpper()));
}
thanks
|
|
|
|
|
How To Deploy ASP.NET Core to IIS ?
|
|
|
|
|
|
So I have this weird (to me) JSON string of "Things":
{
"0":{"Property1":"P0001","Property2":"Value One"},
"1":{"Property1":"P0002","Property2":"Value Two"},
"2":{"Property1":"P0003","Property2":"Value Three"}
} I can make a simple class
Friend Class clsThings
<JsonProperty("Property1")>
Public Property Property1 As String
<JsonProperty("Property2")>
Public Property Property2 As String
End Class and by "manually" (in code) stripping out each individual "Thing" - eg:
{"Property1":"P0001","Property2":"Value One"}
{"Property1":"P0002","Property2":"Value Two"}
{"Property1":"P0003","Property2":"Value Three"} can loop through them one by one and, using Newtonsoft, read them into a collection of classes.
But I am sure there must be a way to do this without the manual steps of extracting each sub-JSON-string (for want of a better word) .....
Newtonsoft Utils wants to create separate classes for each line, which is just sily ...
|
|
|
|
|
You can parse the json using the newtonsoft classes
JObject jo = (JObject)JsonConvert.DeserializeObject(json);
foreach (JProperty p in jo.Properties())
{
string pname = p.Name;
string p1 = p.Value["Property1"].Value<string>();
string p2 = p.Value["Property2"].Value<string>();
}
or you can map the properties to your own object
JObject jo = (JObject)JsonConvert.DeserializeObject(json);
foreach (JProperty p in jo.Properties())
{
string pname = p.Name;
clsThings t = JsonConvert.DeserializeObject<clsThings>(p.Value.ToString());
}
It's csharp but should be fairly easy to convert. "json" contains your json string.
|
|
|
|
|
|
The simplest option would be to deserialize as a Dictionary(Of String, clsThings) . If necessary, you can then ignore the keys, and just read the values.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i am fetching data from db using EF. when i fetching then i am filtering and sorting data too.this way i am sorting by column name. huge line i have to write which looks not good.
switch (SortColumn)
{
case "CompanyName":
ViewBag.OldSort = "CompanyName";
if (SortColumn.Equals(CurrentSort))
{
customer = customer.OrderByDescending(m => m.CompanyName);
ViewBag.CurrentSort = "";
ViewBag.SortOrder = "desc";
}
else
{
customer = customer.OrderBy(m => m.CompanyName);
ViewBag.SortOrder = "asc";
}
break;
case "ContactName":
ViewBag.OldSort = "ContactName";
if (SortColumn.Equals(CurrentSort))
{
customer = customer.OrderByDescending(m => m.ContactName);
ViewBag.CurrentSort = "";
ViewBag.SortOrder = "desc";
}
else
{
customer = customer.OrderBy(m => m.ContactName);
ViewBag.SortOrder = "asc";
}
break;
case "ContactTitle":
ViewBag.OldSort = "ContactTitle";
if (SortColumn.Equals(CurrentSort))
{
customer = customer.OrderByDescending(m => m.ContactTitle);
ViewBag.CurrentSort = "";
ViewBag.SortOrder = "desc";
}
else
{
customer = customer.OrderBy(m => m.ContactTitle);
ViewBag.SortOrder = "asc";
}
break;
case "Address":
ViewBag.OldSort = "Address";
if (SortColumn.Equals(CurrentSort))
{
customer = customer.OrderByDescending(m => m.Address);
ViewBag.CurrentSort = "";
ViewBag.SortOrder = "desc";
}
else
{
customer = customer.OrderBy(m => m.Address);
ViewBag.SortOrder = "asc";
}
break;
case "Default":
ViewBag.OldSort = "CompanyName";
customer = customer.OrderBy(m => m.CompanyName);
ViewBag.SortOrder = "asc";
break;
}
please see for 4 columns i have to write so many line of code. suppose if i need to work with 40 columns then how many more line i need to write. so tell me best option to minimize the code for sorting when working with EF.
|
|
|
|
|