spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » C# » Page 3
Searching a enum description containing a slash
Enum.Parse takes a string argument representing the name of the enum value, not the description, i.e. what Enum.ToString() returns. You'd need a method that finds an enum value by description, like this one: public static TEnum GetEnumByDescription<TEnum>(string desc) where TEnum : struct { if(string.IsNullOrEmpty(desc)) { return default(TEnum); } foreach(var field i

Categories : C#

C# how to properly make a http web GET request
Servers sometimes compress their responses to save on bandwidth and increase how responsive their site is, so when this happens, you need to decompress it before trying to read that response, fortunately the .NET framework can do this automatically but we have to turn the setting on. Here's an example of how you could achieve that. string html = string.Empty; string url = @"https://api.stackexch

Categories : C#

Get ComboBox selected value form Form1 to another Form2
This type of question has been asked and answered many times, and in different versions. I would suggest looking at a few of the following I have posted in the past... This example shows two forms where second form is passed as a parameter the first form's instance. Then, from public methods exposed on the first, the second can call them to get the values. It is your discretion on if you want

Categories : C#

Pixel Format conversion
It's PixelFormats.Prgba64, reading MSDN you may be confused because there is a small error in documentation: it states it's 32 bit per channel. Prgba64 is a sRGB format with 64 bits per pixel (BPP). Each channel (blue, green, red, and alpha) is allocated 32 bits per pixel (BPP). Each color channel is pre-multiplied by the alpha value. This format has a gamma of 1.0. It's obviously wrong beca

Categories : C#

Why does my download queue break when called faster after each other?
Queues are not designed to be accessed from multiple threads, and any number of things can go wrong when you do so. You should use a ConcurrentQueue or a BlockingCollection (which uses a ConcurrentQueue), as it is specifically designed to be used from multiple threads.

Categories : C#

How to define XML namespaces to be incuded in the header of XML request which will be send via invoke of a Web Service call?
You'll need to ensure that the http://docs.oasis-open.org/... Namespace is included in the SoapHeader, e.g. [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", IsNullable = false)] public partial class UsernameToken : System.Web.Services.Protocols.SoapHeader { // Namespace is also available here if d

Categories : C#

eventlog source - string/message table lookup failed
Try to pass in an ID like this: try { EventLog.WriteEntry("LogSource", "test", EventLogEntryType.Error, 6285); } catch { MessageBox.Show("Could not write to log."); } Also, if you have a custom message file, try taking out the lines which say Severity= XXX and Facility=XXX.

Categories : C#

What is the idea behind IIdentity and IPrincipal in .NET
IIdentity is just used for the user's authenticated identity, regardless of what roles they may have. IPrincipal is used to combine a user's identity with the authorized roles they have in a given security context. For example, you can use a third-party login provider, like Facebook or Google, to get the user's identity, but you will not get a principal from those providers, as they don't provi

Categories : C#

How can the Wix Installer distinguish target builds?
With the following code you can define producttarget WiX variable based on Configuration MSBuild property: <!-- Somewhere in .wixproj --> <PropertyGroup> <DefineConstants Condition=" '$(Configuration)' == 'Debug' ">$(DefineConstants);producttarget= (Demo)</DefineConstants> <DefineConstants Condition=" '$(Configuration)' == 'Release' ">$(DefineConstants);produ

Categories : C#

Verifying if method was called with Moq
On the line 1 you setup the mock, but line 2 overrides the whole mock, so now mockContext.TestCaseExecutions returns mockTestCaseExecution.Object - mock that hasn't been configured. You call Add on mockTestCaseExecution object, so you should set up there. //Mock of one of it's tables var mockTestCaseExecution = new Mock<DbSet<TestCaseExecution>>(); mockTestCaseExecution.Setup(x =>

Categories : C#

Send json data to SQL Server 2008
I succeeded to create stored procedure with parameter json string contain multiple data table. It was simple to parse the Hierarchy table created with parseJSON (see article Consuming JSON string in SQL). According with this, I think is a good way to send multiple data table to SQL. I want to mention: I don't have any experience with SQL Server. So maybe the question is stupid (was negative vote

Categories : C#

Cannot validate in MVC 5 authentication with both UserName and Email
Looks like in your call to SignInManger.PasswordSignInAsync you are still sending in the email as the username that you would like to use to authenticate instead of the UserName property. var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);

Categories : C#

Unioning two LINQ queries
The types of your two sequences are not the same, so you can't do a Union. new { MyCustomer.CustomerId, MyCustomer.Name, g.Address1 }; new { MyAddress.Address1, g.Name }; Try making sure that the fields have the same names and types in the same order.

Categories : C#

How to block a number in Twilio
Hi I believe that Twilio does support industry standards such as Stop, Block and Cancel. You can read more about this here, http://www.twilio.com/help/faq/sms/does-twilio-support-stop-block-and-cancel-aka-sms-filtering. From that I take it that Twilio will respect a clients wish to prevent receiving further messages, should they choose to do so.

Categories : C#

Pass object attribute to controller
I think the name that asp.net mvc will bind for your parameter is SelectedScenario_ID, try this: [HttpPost] public ActionResult Index(int? SelectedScenario_ID) { /// code... } On the other hand, you could use just a DropDownList, for sample: @using (Html.BeginForm("Index", "CharterSchoolParameters", FormMethod.Post)) { @Html.DropDownList("selectedScenarioId", Model.ScenarioList) } [Http

Categories : C#

C# nHibernate programatically set db password
Your best bet is probably to use Configuration.GetProperty and Configuration.SetProperty to modify the configuration defined in your hibernate.cfg.xml file: var configuration = new Configuration() .Configure(); const string connectionStringKey = "connection.connection_string"; string connectionString = configuration.GetProperty(connectionStringKey); connectionString = Regex.Replace( con

Categories : C#

How to add node at mouse click location on canvas?
Figured it out. I had to use this in my addNode_MouseDown method: Canvas.SetLeft(ellipse, e.GetPosition(canvas1).X); Canvas.SetTop(ellipse, e.GetPosition(canvas1).Y); And then I just subscribed to it in the canvas.

Categories : C#

Register boolean in Container
The exception message is a bit misleading, since Simple Injector disallows you from registering primitive types (such as Boolean) in the container, so in fact the container is advising you something that is impossible to do. The reason that Simple Injector disallows you from registering primitives such as int, bool, string is that those types are ambiguous. DI containers in .NET inject services

Categories : C#

ASP MVC or/and Networking issues
Happy End Thanks to everyone who tried to help. So, if by some strange chance someone gets in the same position and happens to read this, here is what happened. It is easy to see that our setup is a little archaic (and that is me trying to put it mildly). So, one of our sheriffs(administrators) read or remembered that the Windows Server 2003 starts having trouble with SSL at some point. Even th

Categories : C#

Managing Single Quotes while calling on a Stored Procedure
Sort answer: replace the single quote with two single quotes when composing your query. That's how you escape a single quote in SQL Server. I.e: var escapedValue = originalValue.Replase("'","''"); Good advice: as told in all the comments, don't compose the query in this way, and use parameterized queries or stored procedures, and pass the parameter values: you'll avoid problems like numbers and

Categories : C#

Connection String to connect a SQL Server using another windows account
Yes, and quite trivial. Do NOT put username and password into your connection string. Use username and apssword to impersonate the other user How to specify the user in a C# Thread Connect from that thread. Finished. Internal security will now work with the impersonated user. Impersonation is explicitly done to NOT have to deal with username and password.

Categories : C#

DynamicTableEntity PartitionKey and RowKey
Simple answer is that you can't. PartitionKey and RowKey are system defined attributes (along with Timestamp) and you can't change their name. What you could do is define two more custom attributes for Env and Ver if you need to access the properties by these names in your application. DynamicTableEntity entryEntity = DynamicTableEntity(env,ver); entryEntity.Properties.Add("Id", id); entryEntity.

Categories : C#

The property content is set more than once.. WPF
You're missing the UserControl.Resources tag: <UserControl x:Class="Tackle.View.Menu" ...> <UserControl.Resources> <!-- You're missing this --> <CollectionViewSource x:Key="dogs" Source="{Binding}" > <!-- Change x:Name to x:Key here --> <CollectionViewSource.GroupDescriptions> <PropertyGroupDescription P

Categories : C#

How to change asp:ListView DataPager page from codebehind (c#)
I found a scenario that is similar to yours (http://www.4guysfromrolla.com/articles/021308-1.aspx) and I verified that the sample application works calling SetPageProperties() at run-time. Be sure to change the last "databind" argument in your SetPageProperties call to from False to True: pager.SetPageProperties((int)Session["PageNumber"] * pager.PageSize, pager.MaximumRows, true); then mak

Categories : C#

Case-insensitive "contains" in Linq
the easy way is to use ToLower() method var lists = rec.Where(p => p.Name.ToLower().Contains(records.Name.ToLower())).ToList(); a better solution (based on this post: Case insensitive 'Contains(string)') var lists = rec.Where(p => CultureInfo.CurrentCulture.CompareInfo.IndexOf (p.Name, records.Name, CompareOptions.IgnoreCase) >= 0).ToList();

Categories : C#

Bootstrap Button_Click Event Not Firing
My guess is that you are getting a normal <button> mixed up with an <asp:Button>. Your current implementation wants to run a javascript function name btnSubmit_Click and does not have any connection to your C# code-behind. ... <asp:Button type="submit" CssClass="btn btn-primary" OnClick="btnSumbit_Click" runat="server">Register</asp:Button> ... I haven't been able to te

Categories : C#

catch OnVisibilityChanged events
I was tired of searching. I did the stupid but rapid thing: dockingManager.DockControlActivated += handler1; dockingManager.DockControlDeactivated += handler2; dockingManager.DockMenuClick += handler3; dockingManager.DockStateChanged+=handler4; dockingManager.DockStateChanging += handler5; dockingManager.DockVisibilityChanged += handler6

Categories : C#

In C#, SQL connection is printing: 'System.Data.SqlClient.SqlDataReader'
SqlDataReader.ToString() method returns it's full-typed name of type. That's why it returns System.Data.SqlClient.SqlDataReader. Actually, this is done by Console.WriteLine because there is no overload called Console.WriteLine(SqlDataReader) and that's why it calls Console.WriteLine(object) overload and inside this method, object.ToString() will called probably. Read() method reads your result r

Categories : C#

Action parameter object property causes ArgumentNullException when nullable struct
ASP.NET MVC's default model binder uses Activator.CreateInstance(System.Type) to create your model and its properties and it has no special magic in place for handling Nullable<> types. Since you're using a Nullable<SpecialDate> for "SpecialDateB", MVC gets a null reference when calling Activator.CreateInstance(System.Type) as it has no initial value. MVC then updates the model state

Categories : C#

@section not rendering in Razor - MVC C# .NET 4.5
did you try with just RenderSection("AdditionalMeta", false); instead of @if (IsSectionDefined("AdditionalMeta")) { RenderSection("AdditionalMeta"); } refer here for documentation

Categories : C#

How to secure multiple connection strings in an application
There's no easy answer to your question. It really depends on how sensitive is your information and how much an attacker would want to get this information. The reason for this is simples: .NET applications can be decompiled easily (even the obfuscated ones). That means if you store an encrypted something, you would need to store a encryption key anywhere. By using decompile, an attacker could ta

Categories : C#

Pass javascript variable as argument in ASP.NET MVC form
As far as I know it is not possible. At the begining your cshtml file is parsed by Razor, and after that scripts are running. You can always modify elements using jQuery by accessing them via ID.

Categories : C#

[C#]Get Sourcecode of Website (404 ERROR)
You will probably have to set the user agent to a known browser for a lot of sites as they will reject requests from unknown "browsers". Try this before you call request.GetResponse var agent = "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)"; request.Headers.Add("user-agent", agent);

Categories : C#

C# Setting dependentAssembly for dll
You should do this in your original App.Config file, if the assembly is loaded as reference in an application. <dependentAssembly> <assemblyIdentity name="YourAssemblyName" publicKeyToken="xxxxx" culture="en-us" /> <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" /> </dependentAssembly>

Categories : C#

Set static resource in code
A StaticResource is static. You can't change them once the application has compiled. For this purpose, there is DynamicResource: A DynamicResource will create a temporary expression during the initial compilation and thus defer lookup for resources until the requested resource value is actually required in order to construct an object. Also note that you can find the reference to the other

Categories : C#

ASP .NET model within itself
because when Find methos is invoked from db.Documents it search in every Document element. your serach aim to search inside a field for each document and that is why you should use Include("SimilarDocuments") Documents Document -> this is where db.Documents.Find search SimilarDocuments --> you want to search here

Categories : C#

How to configure many-to-many entity framework relationship, but to same object? EF6
Why don't you just do this? public MyObject{ public long Id { get; set; } public string Name { get; set; } public ICollection<MyObject> Parents { get; set; } public ICollection<MyObject> Children { get; set; } }

Categories : C#

Multiple on clause from DataTable to DataTable via LINQ
Instead of the LoadDataRow + CopyToDataTable approach i would always prefer a simple foreach where i add those rows in the query. Thats much more clear and doesn't rely on side-effects. You can join on the string and put both rows in an anonymous type: var query = from r1 in dt1.AsEnumerable() join r2 in dt2.AsEnumerable() on r1.Field<string>("TEST2") eq

Categories : C#

How to add Checkboxes to Listview from Code behind using C# in WPF
Its really easy just do this.. In Design view (Xaml): <Window.Resources> <DataTemplate x:Key="Chk_Field" DataType="{x:Type GridViewColumn}"> <CheckBox IsChecked="{Binding chk}" /> </DataTemplate> </Window.Resources> In Code behind: GridView gridview = new GridView(); Window window = Application.Current.MainWindow; DataTemplate s = (DataTemplate)windo

Categories : C#


Recently Add
Process MainWindowTitle not displaying for all running processes
SendGrid Tutorial resulting in Bad Request
Dropdown list from table in ASP NET MVC
Newtonsoft.JSON Serialization Array, Object, or Null
Using LINQ to select a byte array
How to stop scripting?
C# access to object property after json decode
How to kill instance of Word/Excel File in C#
Datatypes for MemoryStream.Capacity vs MemoryStream.Length
How to remove a selected row from a table when using KnockoutJS
SqlCommand returns null even tho there is data in the database
Replacing words in a body of text from array
C# dropping milliseconds from Java SOAP call
C# Deserialize list in JSON
Deserialize xml by linq, default with many elements
How to Access Grid View from hub section Data Template Windows phone 8.1 in C#
Input dialogue popup on mouse click
WPF: Binding to MainWindow Property SOLVED
Why is setting a field many times slower than getting a field?
Change multiple materials in one GameObject in Unity3D
.NET MVC error client side with custom validation attribute
Windows Search Service - text saved in ansi (codepage 1251) format - search for non-english symbols gives no result
String.Split - Omit empty array elements OR below a certain length
RequiredFieldValidator does not validate when ValidationGroup applied
Which WCF's extension point should be used for setting context for each operation?
Determine var type depending on ternary (?) Operator on int array
Resolving Windows phone 8.1 Compilation Error: GetENumerator
Specific Ordering of a List of Objects using LINQ
'string' does not contain a definition for 'Fill' and no extension method 'Fill' accepting a first argument of type 'string' could be found
how can ı pass data from serverside to clientside
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.