w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » C# » Page 1
How to get an object from the webgrid.
Instead of using @RenderPage try UserSearchDisplayModel user = grid.Rows[grid.SelectedIndex].Value; @Html.Partial("_AdminUserDetails", user) Works for me.

Categories : C#

Can I override WebAPI OData service document?
I do not experience the behavior you are seeing regarding the ResetDataSource action and the GetNearestAirport function not appearing in the Metadata Service Document. I have not heard of anyone having that issue. Will chat with the OData team this week about it. In regards to the overriding of the Metadata Service Document, I do not believe there is any way at this time to change it. Allowing ch

Categories : C#

Insufficient buffer size using WriteableBitmap?
Your overlay.Format.BitsPerPixel / 8 will be 1 (because it's a gif), but you're trying to copy it to something that is not a gif, probably BGRA (32 bit). Thus you got a huge difference in size (4x). .WritePixels should take in the stride value of the destination buffer, but you past it the stride value of the overlay (this can cause weird problems as well). And finally, even if it went 1

Categories : C#

Show Contact List like whatsapp does [Windows Phone 8.1]
How to achieve the LongListSelector jump list in a wp8.1 windows runtime app Jumplists im afraid. In Silverlights contacts access is pretty fast but in XAML apps its a little bit slower (much more slower) so i was thinking in a way to make it work on XAML. @sibbl: Jumplists and your posts combined its a good way.

Categories : C#

EF 6.1.1 - The relationship could not be changed because one or more of the foreign-key properties is non-nullable
When you want to remove items in a 1-many collection from the database you have to mark each item for delete, e.g. like so: foreach (var book in record.Books) { context.Books.Remove(book); } context.SaveChanges(); It's a nuisance sometimes. When you Clear a collection navigation property, EF errs on the side of caution and tries to only break the association without deleting the items, i.e.

Categories : C#

How work with JSON correctly
The easiest way is to use the JSON to class pasting functionality of Visual Studio: First of all, convert your JS object to a JSON string (e.g. with this tool). Copy the JSON output into clipboard and go into some class in Visual Studio. Use Edit > Paste Special > Paste JSON As Classes. You should get the following output generated: public class Rootobject { public string kind { get;

Categories : C#

Custom metadata for service stack
Please see the documentation on modifying ServiceStack's built-in metadata templates: The VFS lets you replace built-in ServiceStack templates with your own by simply copying the metadata or HtmlFormat Template files you want to customize and placing them in your Website Directory at: /Templates/HtmlFormat.html // The auto HtmlFormat template /Templates/IndexOperations.html // The /meta

Categories : C#

Selenium WebDriver 2.44 Firefox 33
It was a version problem after all. It turns out if you're updating Selenium via nuget, you need to be aware of which project the package manager console is pointing at. I'd managed to update my main project to Selenium 2.44 but my test project was still on version 2.40.

Categories : C#

Trying to make use array.clear() but Index was outside the bounds of the array keeps popping out when I run the program?
Because the third parameter indicates the number of elements to clear, you are passing the size of the entire array. You only need Array.Clear(compartmentno, i, 1), as it seems like there is one element you wish to clear. It would be helpful if you could explain more about what this code is supposed to do. Also, instead of using six associated arrays, consider creating a class to store your info

Categories : C#

Merge existing list with an 'update' list
Okay, thanks to the tip of Piyush I figured out a rough way (needs optimisation badly, but works generally): 1) Store your original list in a variable (oldList got passed from a different class) Subcategory OriginalList = new Subcategory(); OriginalList = oldList; 2) Generate a dictionary containing all to-be-updated categories and products 'prod' is the base tree, and you will go recu

Categories : C#

Calling a web method from Windows Phone 8
You can use HttpClient using (var client = new HttpClient()) { var resp = await client.PostAsJsonAsync("http://your host/Login.aspx/Login", new { username = "", password = "" }); var str = await resp.Content.ReadAsStringAsync(); }

Categories : C#

How to cast datetime of mysql to datetime of asp.net
First of all, let's fix this to use parameters: //I'm less worried about this query, as m and are likely integers. // I still don't approve of the string concatenation, but I'll leave it alone for now String q6 = "select date from lot LIMIT " + m + "," + n + ""; MySqlCommand c6 = new MySqlCommand(q6, cn); DateTime d = (DateTime)c6.ExecuteScalar(); //This should work just fine. //but parameter

Categories : C#

Enterprise library logging Database trace listener with custom parameter input
You will either need to create a custom trace listener that knows how to log to your table/stored procedure or modify the logging table/stored procedure to be in a format that Enterprise Library expects. Here is a sample database trace listener for SQL Server. It could be a good starting point for you if you decide to create a custom trace listener. Also, since you are using Oracle you will nee

Categories : C#

Using an Expression in a compiler-generated expression tree
You can't mix arbitrary Expression instances with compile-time expression trees. What you can do is construct a new expression tree with specific nodes replaced, so you can have i => i + marker and then construct a new tree with the marker node replaced by your runtime expression. This requires writing an appropriate ExpressionVisitor: public static class ExpressionExtensions { public static

Categories : C#

Creating a C# service to monitor changes in infinite loop
You need to use Thread.Sleep() to avoid busy waiting or, better yet, just use a System.Timers.Timer (or one of its cousins) to wake up when you want. You also need to start your service in OnStart() instead of trying to do all its work there; that means scheduling an event handler (e.g. via Timer) or starting a new thread so that OnStart() can return on its original thread. The Windows Service sys

Categories : C#

SignalR Transports when using the .NET Client
The SignalR .NET client supports up to 3 transports: WebSockets (.NET 4.5 only) Version 2.2.0 of the SignalR client will also support the WebSocket transport in universal Windows apps. Server-sent events Long polling There is also the default auto transport that will try to use the best transport available. For example, it will initially try to start a connection using WebSockets, but if that

Categories : C#

Reason to make Point3D a reference type deriving from Point2D and implementing an IPoint3D interface?
This is an opinionated question and well, here is an opinionated answer... That is way too much abstraction and interfacing for something so simple. I would simply have immutable vector types of what I need. Even if the Vector3 changes constantly, you are doing this: ObjectA.Vector3 = SomeTransformationFunction(ObjectA.Vector3); Vector3 could totally be an immutable type here. I am having a

Categories : C#

Ordering elements in a list by a chain
Interesting question! As pointed out by starlight54, this approach is called a linked list, in particular a doubly linked list. Although I think that strictly speaking, in a linked list the references to other nodes are part of the nodes themselves. In db terms: the database record itself has foreign keys to the next and previous nodes (i.e. a doubly linked list). But that doesn't really matter fo

Categories : C#

How to convert a list of objects to a list of strings in c#?
I got the answer. It was very simple. Updated code, foreach (DataRow dr in dt.Rows) { lstweeks.Add( { new GetData{week = dr["WK"].ToString()} ); }

Categories : C#

ASP.NET Razor Cshtml To Pdf loses HTML formatting - NonMVC
I haven't used iTextSharp before, but in the examples I've seen online, they don't use all of the many writers you have. I'm suspecting that one of those is stripping out the HTML. Can you try a simpler path from StringBuilder to the html parser? htmlparser.Parse(new StringReader(sb.ToString())); These two pages seem to have had the same issue, but said they found a resolution. Their code is s

Categories : C#

XSLT transform: how to preserve the element's attributes during transform?
Yeah, it's a common easy mistake. The <xsl:copy> only copy the element itself, it's equivalent to <xsl:element name="{name()}">. You need to explicitely copy attributes nodes. For example, just switch your default template by : <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:t

Categories : C#

How does one call a method with Tuples?
Tuples are just generic objects. However you use the tuple, just imagine that you created a class with that many Items of the appropriate type. For instance, Tuple< string, int, int> will give you myObj.Item1 as a string, and Items 2 and 3 as integer. You can use it like this: new Tuple<string, int, int>("Steve", 15, 22) In the case of a list: var myList = new List<Tuple<doub

Categories : C#

Setting Session data in another Controller
use a service (helper) classes to share common code between controllers: public class ReportService() { public void SetReportValues(string pReportName, Dictionary<string, object> pParameters) { HttpContext.Current.Session["ReportName"] = pReportName; HttpContext.Current.Session["ReportParameters"] = pParameters; } } ReportsController: public void Report(ReportWrapper

Categories : C#

How to store the last few numbers as a variable in a table row
Not sure what format you want to store it as, or what you want to do with it after, but... Edit: Added an if check for length to avoid index out of bounds condition. Also corrected syntax- SubString() => Substring() int count = 0; foreach(var row in table){ string temp = row.ID.ToString(); count += (temp.Length > 5)? Convert.ToInt32(temp.Substring(temp.Length-5, 4)) : Convert.ToInt32(

Categories : C#

Cannot implicitly convert type 'int' to 'System.Collections.Generic.List'
It is reasonable the error you get, because RemoveAll returns the number of removed stocks. This is an integer. Then you try to assign this to the variable called ticker, which holds a list of objects of type Stock. That you probably want is to remove all the Stocks that their TickerSymbol is gm and then write the Stocks that they have been left in ticker to the console. In order to do so, you co

Categories : C#

SqlHelper ExecuteDataSet with named parameters?
SqlHelper is obsolete. It was replaced by the Database object from MS Enterprise Library, but this is also obsolete. What functionality are you trying to extrude from it? You might be better off building your own abstraction layer using the Enterprise Library as a starting point.

Categories : C#

How did the code execution get inside this 'if' statement?
No, StartWith isn't buggy, and works as expected. Try the minimal code below. Reduce your code to the minimum amount to reprouce the problem. Does this happen everytime? Does it happen with more than one candidate string? Or only that string? Something else is going on sorry, the following writes Doesn't start static void Main(string[] args) { string cleanUrl = "123.123.123.123

Categories : C#

Searchable Listbox using two different item collections
From what you are showing, the ListBox l is not initialized, thus .Clear() on the collection is throwing a NullReferenceException. Instantiate the ListBox to fix the problem: ListBox l = new ListBox(); By the way, I tested this, not theorizing.

Categories : C#

How do I setup Selendroid in Visual Studio?
When looking for information on this I came across this post describing unit tests with C# and Selendroid. YMMV. http://pritamsen.wordpress.com/2014/04/11/selendroid-c-code-with-nunit-runner-to-run-on-device/

Categories : C#

Using the OAuth2.0 Token.Credentials for acessing GData
I am not sure how much correct the following approach is but that is what worked for me. Using the service credentials token you can access the GoogleMailSettingsService as follows bool success = credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Result; OAuth2Parameters parameter = new OAuth2Parameters() { AccessToken = credential.Token.AccessToken }; GOAuth2Requ

Categories : C#

Converting and Writing Variable of Type Var to Output File
This worked out great for me. Thank you for the help, everyone. XmlSerializer serializer = new XmlSerializer(typeof(UserReportPreviewListDto[])); TextWriter WriteFileStream = new StreamWriter("serializer.xml"); serializer.Serialize(WriteFileStream, results); WriteFileStream.Close(); Learned something awesome today that'll help out a ton in the future, I have no doubt. Thanks again!

Categories : C#

XAML equivalent of a foreach
Foreach is achieved with a list view like ListBox, ListView, etc. the simplest form is the ItemsControl class (no scrolling, etc.). The list is passed to the view using the ItemsSource property. The repeated code block is usually defined in the ItemTemplate template. Have a look at this answer: http://stackoverflow.com/a/3063208/876814

Categories : C#

install WIX installer application in C: partition instead of Program Files folder
Try this (untested; but probably enough for what you need to do): <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="INSTALLFOLDER" Name="Wixdemoapplication" /> </Directory> Otherwise, can do some other fun stuff, like: Add this custom action to Product.wxs: <CustomAction Id="SpawnBrowseFolderDialog" BinaryKey="CustomActions" DllEntry="SpawnBrowseFolderDialog"

Categories : C#

Universal App Data Binding accessing data from code behind
Okay, just a few minutes after posting I've realized I was going at it from the wrong angle. Instead of assigning a "Tapped" event to the StackPanel, there's a generic ItemClick event for the ListBox, which can access the bound object via e.ClickedItem (plus casting).

Categories : C#

Split List into Sublists with LINQ
Honestly it's easier to do this in a traditional manner rather than with Linq, since the transformation method required for each element in the sequence requires knowledge of all previous elements. So, you could do something like this: public static IEnumerable<List<T>> Partition<T>(IEnumerable<T> list, Func<T, long> getValue, long maxSum) { long sum

Categories : C#

How to access animation parameters in Unity C#?
You can retrieve boolean Animator parameters by using the Animator.GetBool() method. Animator animator; void Start() { animator = GetComponent<Animator>(); } void Update() { var attacking = animator.GetBool("Attacking"); }

Categories : C#

How do I consume this xml web service in c#?
1) Add a service reference to your project. 2) See generated classes with object browser. 3) Use generated service client var webServiceSoapClient = new Q26998366_ConsumeAsmx.Dixon.WebServiceSoapClient ("WebServiceSoap"); foreach (Dixon.User user in webServiceSoapClient.Data()) { Console.WriteLine(String.Format("Name: {0} Pass: {1} Salt: {2} " , user.username, user.password, use

Categories : C#

how to change color of comboBoxEx Dotnetbar as form has StyleManager with different style
below is code which solved my problem i used ComboBox.DefaultStandalone property instead of ComboBox.Default LinearGradientColorTable linGrBrush = new LinearGradientColorTable( Color.DarkGray, Color.DarkGray); Office2007Renderer renderer = GlobalManager.Renderer as Office2007Renderer; if (renderer == null) return; Office2007ColorTable table =

Categories : C#

Checkedlistbox refresh not working
You aren't removing the item from the control: if (dialogResult == DialogResult.Yes) { File.Delete(item); checkedListBox1.Items.Remove(item); } Best to put some Try...Catch blocks around such operations.

Categories : C#




© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.