w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » C# » Page 2
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#

Combining two lists with C#
There is the Enumerable.Zip extension method. The second argument tells the method what to do with each pair of elements. IEnumerable<Tuple<int, int>> pairs = a.Zip(b, Tuple.Create); IEnumerable<int> sums = a.Zip(b, (x, y) => x + y); If one collection is larger than the other, the remaining elements of the larger collection will be ignored.

Categories : C#

Simplify nested loops?
You need a recursive function foreach (var i in mlist) { checkChildren(i); } and then void checkChildren( List i ) // i is of type List? { if (i.key == dto.under.ToString()) { // add this as a child i.children.Add(m1); // what is m1? you may have to pass // this in as a parameter. I am not // really sure what it is } if (i.children.

Categories : C#

Binding to a TextBox inside an ItemsControl ItemTemplate
You cannot bind to elements in a collection and then change the element itself--you can only change properties of this element through the binding. In other words, given the following collection [ "one", "two", "three" ] through a binding such as <TextBox Text="{Binding Words[0]} /> <!-- the word "one" is displayed in the tb --> if you change "one" to "derp" you would not al

Categories : C#

Fill a rectangle with an image using Mono Cairo Library
I found the solution. I was setting the source at the wrong place. Below is the right code Cairo.Rectangle imageRectangle = new Cairo.Rectangle(50, 100, width, height); ctx.NewPath(); Cairo.ImageSurface imgSurface = new Cairo.ImageSurface("C:/Temp/Image.png"); float xScale = (float)imageRectangle.Width / (float)imgSurface.Width; float yScale = (float)imageRectangle.Height /

Categories : C#

Multiple colored Activity Label element on Xamarin.Android
Look at SpannableString in the Android documentation. http://developer.android.com/reference/android/text/SpannableString.html var textView = FindViewById<TextView>(Resource.Id.my_label); var span = new SpannableString("My Label"); span.SetSpan(new ForegroundColorSpan(Color.Red), 0, 2, 0); // "My" is red span.SetSpan(new ForegroundColorSpan(Color.Blue), 3, 8, 0); // "Labe

Categories : C#

filesystemwatcher check last detection
Create a timestamp that represents the next valid time to process the event. Then, in the event handlers, check the current time against that time. Public Class MyClass Dim NextValidTime as DateTime public sub Some_Event_Handler() If Now() > NextValidtime Then 'do stuff NextValidTime = DateAdd(DateInterval.Second, 1, Now) Else ' Not

Categories : C#

Non-generic implementations of generic interfaces
Just because ExampleEntry can be implicitly converted to an IEntry does not mean that an IRow<ExampleEntry> can be converted to an IRow<IEntry>. If IRow is covariant with respect to its generic argument, then yes, that would be possible, but it's not as it stands, so the implicit conversion isn't possible. If you could implicitly convert an IRow<ExampleEntry> to an IRow<IEnt

Categories : C#

From a API stand point, wait for a task -- but don't block UI
First off, you need to separate your concerns. MyApiManager should not know anything about UIs. It manages APIs, and according to the Single Responsibility Principle, that's all it does. Read Stephen Toub's Should I expose synchronous wrappers for asynchronous methods? It should be the UI event handler's responsibility to make sure MyApiManager does not block the UI. So, change your event hand

Categories : C#

How can I convert my query featuring RowNumber() to LINQ?
This works in memory with an array. Not sure how well it will translate into database calls. (Update: restructured code so the important part is on top) void Main() { var Emps = Emp.GetData(); var q = (from d in (from e in Emps group e by e.DeptNo) select d.Take(2)).SelectMany(e=>e); q.Dump(); } // Boring setup details class Emp { public int EmpNo

Categories : C#

Understanding the structure
That's because Class2 become a nested class. You can create it like this: Class1.Class2 class2 = new Class1.Class2(); then you can use his property like all normal instances: class2.Age = 0; class2.Dob = 0; But i think that waht you are trying to achieve is to have a property to the type of your Class2: public class Class1 { public string FirstName { get; set; } public string LastNa

Categories : C#

How do you change an enum value to a more readable string that is bound to a UltraGrid?
I just create a property that returns the description and bind to it public override string UserTextOp { get { Type enumType = typeof(enumTextCond); string name = Enum.GetName(enumType, cond1SelectedKeyEnum); if (name != null) { FieldInfo field = enumType.GetField(name); if (field != null) { DescriptionAt

Categories : C#

Add data to a TextBox from a DropDownList in a DetailsView field
Can you try this on code behind? protected void DetailsView1_ItemCommand(object sender, System.Web.UI.WebControls.DetailsViewCommandEventArgs e) { if (e.CommandName == "Update") { DropDownList yourddl = DetailsView1.FindControl("yourdropdownlist"); if (yourddl.SelectedIndex > 0) { var tbox = DetailsView1.FindControl("yourtextbox"); tbox.text =

Categories : C#

Accessing XML RPC Interface
i finally found the solution. you still have parse the xml encoded response but now i finally get an response. System.Net.ServicePointManager.Expect100Continue = false; byte[] requestData = Encoding.ASCII.GetBytes("<?xml version="1.0"?><methodCall><methodName>system.listMethods</methodName></methodCall>"); HttpWebRequest request = (

Categories : C#

Am I obliged to call EndPeek after using BeginPeek?
Giving a proper answer to this question takes some effort, because the short answer ("no") could be misleading. Does the API description explicitly say you must call EndPeek() for every call to BeginPeek()? Not in any topic I could find, and not only that, it appears to state the opposite here: To use BeginPeek, create an event handler that processes the results of the asynchronous operatio

Categories : C#

MVC RouteConfig routes one path to Controller but not another
By default, MVC does not route static files and just tries to serve a static .css file under the requested path. Just remove the .css ending and the route will be used. Edit: To be clearer the IIS tries to serve these static files before the MVC routehandling even comes into play.

Categories : C#

How to map a class containing a property that is a derived class
I think nHibernate should figure it out, if you have subclasses mapped correctly. Just mapp a relationship between Foo and Thing (https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping - chapter Relationships - you have maybe one-to-one or many-to-one).

Categories : C#

How to unload menus (UIViewControllers)
viewWillAppear: method gets invoked every time the controller's view is about to be displayed. Whenever you make a transition to and fro from a controller, it would be invoked. From Apple's documentation(iOS Developer Library) : This method is called before the receiver's view is about to be added to a view hierarchy and before any animations are configured for showing the view. You can

Categories : C#

how to pass a List in the model as a parameter of an ajax call?
If I am reading the question correctly you want to return a JsonResult and just return a List<Persons>. You'll then get that result and bind it to whatever you are displaying the results in: a grid, list, etc. You'll likely want to look into some sort of client templating library to make this easier. You can certainly use jQuery to do all this, but something like handlebarsjs would make it

Categories : C#

ASP.NET MVC on Azure Run Job "Every Hour"
As it was already mentioned in the comments, you would be better off separating "long-running" task from your website, you can still keep it in the same solution, as separated project, to make sharing business logic code simpler and just deploy to two different environments - Website + WebJob, Website + WebWorker You can try to mitigate the issue with long running task on IIS, see some resources

Categories : C#

TPL Dataflow Consumer to Process Multiple Items at a time
Your use of TPL Dataflow is rather strange. Normally, you'd move the consumption and processing into the flow. Append a TransformBlock to call the webservice. Delete ConsumeValues. ConsumeValues executes sequentially which is fundamentally not what you want. Instead of BoundedCapacity I think you rather want MaxDegreeOfParallelism.

Categories : C#




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