spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » C# » Page 2
C# How to change FileAttributes from Normal to Directory
According to the documentation for the SetFileAttributes API function, which is what the call to File.SetAttributes resolves to: Files cannot be converted into directories. If you want to get information from that device, you'll have to read raw sectors using low level device I/O. It's possible, but a lot of work. If you're serious about getting information from that device, do not attempt

Categories : C#

Fill one row of a two-dimensional array with a single-dimensional array
You should change your syntax: var data = new string[rows.Count()][]; // This should be valid, an array of arrays data[0] = GetHeaders(); var i = 1; foreach (var row in rows) { data[i][0] = row.First; data[i][1] = row.Last; data[i][2] = row.Phone; i++; }

Categories : C#

NUnit result are different in debug and release
Posting an answer because a comment would be too small to hold what I want to say... There is no reference to PresentationTraceListener on the internet-- how it treats the TraceListener is important because AFAIK the PresentationTraceListener is what calls the Write/WriteLine methods of the TraceListener (possibly indirectly via TraceSource) This code below compiles in a brand new project. If I

Categories : C#

callback excutes on server side or client-side?
Client side! OnClientClick property is for client side javascript code. Refer this documentation http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick(v=vs.110).aspx

Categories : C#

braces and curly brackets when generating interface with codeDom
When you use CodeDom, I understand you have some options on how code is created. You have to use the CodeGeneratorOptions and set the BracingStyle = "C"; if you want to change the default behavior. Take a look on the Examples section on the following article. http://msdn.microsoft.com/en-us/library/system.codedom.compiler.codegeneratoroptions(v=vs.110).aspx Hope this helps. EDIT Are you gener

Categories : C#

Exception handling in Web API
ASP.NET Web API 2.1 have framework support for global handling of unhandled exceptions. It allows use to customize the HTTP response that is sent when an unhandled application exception occurs. So, do not catch exception in Class Library. If you are required to log exception in Class Library, then re-throw those exception to Presentation. WebApiConfig public static class WebApiConfig { pu

Categories : C#

Changes that web.config in WCF service needed to support Rest
Here is a sample code segment which you can use. here i added sample method which you have to implement in your service class and then I added web config for that WCF service. Hope this will help you to solve your problem. [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/GetNameXML?n

Categories : C#

Why is .NET's File.Open with a UNC path making excessive SMB calls?
I don't really have a specific answer to why the .NET implementation is so chatty, but this behaviour would be due to the implementation of System.IO.FileStream as all that File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); is doing is passing the parameters to the FileStream constructor. public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare shar

Categories : C#

Passing information through viewmodels
First, you shouldn't do a query operation within the ViewModels constructor. You shouldn't do any "expensive" operation within the constructor of a class. Second, ViewModels shouldn't be aware of other ViewModels. So you shouldn't instantiate a ViewModel within another ViewModel. I would suggest a different approach. Instead of trying to pass an ID to the ViewModel directly, do it via an event

Categories : C#

.NET Portable Class Library [Serializable] Attribute
I have created a PCL support library called CSShim that contains a "mock" [Serializable] attribute. If this library is referenced from your PCL library, you can use [Serializable] in your code. Then, when you consume your PCL library in a regular .NET desktop application, the reference to the PCL CSShim is replaced with a reference to the .NET anolugue of CSShim, using the so-called "bait-and-swi

Categories : C#

Dropnet on MVC after redirect
You were on the right track trying to put the DropNetClient instance in the session. Though you only need to store the userLogin object once you call _client.GetToken() then user that user token and secret to create a new instance of the DropNetClient and finish the authentication process. For more info have a look at this answer: http://stackoverflow.com/a/25798991/75946

Categories : C#

using UserPart based Parts in testing
As @Bertrand Le Roy suggested in his comment, the record is null. You are constructing your content item like this: ContentItem usrItem = ContentHelpers.PreparePart(new UserPart(), "User"); If you compare that to the way Bertrand describes the process in his Blog, you'll notice that in addition to creating a BodyPart, he is also creating it's underlying BodyPartRecord. This is required becaus

Categories : C#

Error decompressing gzipstream -- The magic number in GZip header is not correct
You need to insert a line and remove an other: FileStream fs = File.OpenRead(dlgOpen.FileName); byte[] picbyte1 = new byte[fs.Length]; fs.Read(picbyte1, 0, (int)fs.Length); // <-- Add this one byte[] picbyte = Compress(picbyte1); // fs.Read(picbyte, 0, System.Convert.ToInt32(picbyte.Length)); // <-- And remove this one // ... You are reading the image in your code, but something is in the

Categories : C#

Getting an error when i am changing my folder location
I assume that the filename in the path you're using is under 8 characters and so the call to Substring (0,8) is failing. You need to check the length of your filenames before calling substring on them. Assuming that for filenames under 8 characters you just want the whole filename, you can do something like: var charactersToRead = Path.GetFileNameWithoutExtension(m).length < 8 ? Path.GetFileN

Categories : C#

How to override MaxLength, Mask, PromptChar properties of maskedTextBox
About Mask and PromptChar properties, if you want the designer to use your custom default values instead of the base ones, then you have to associate them through some helper class (like a Designer that overrides PreFilterProperties) or to hide the base properties declaring new ones with the same names, like: [Localizable(true), RefreshProperties(RefreshProperties.Repaint)] [DefaultValue('0')] pu

Categories : C#

Changing Event Handler
You'll have to hold onto a reference to the handler that you used to be able to remove it: private ClickEventHandler handler; public void AtribuiEvento(Control c, string evento, string codigo, bool prioritario) { evento = evento.ToLower(); if(evento == "click") { c.Click -= handler; handler = delegate(Object sender, EventArgs e) { ExecuteSnippetUser

Categories : C#

Database first, files extensions and their uses
.tt is T4 template file which generates your Entity Classes and Context. .edmx.diagram contains information that is used by the Entity Designer to render a graphical display of the conceptual model. .Designer.cs contains information that is used by the Entity Designer to render a conceptual model graphically and to define some conceptual model and design-time properties. after vs 2012 this file

Categories : C#

Queue showing empty
It seems to be related to your transaction. You should try to place [TransactionFlow(TransactionFlowOption.Allowed)] on the operation in the service contract. Something like: [ServiceContract] public interface IMSMQService { [OperationContract(IsOneWay = true)] [TransactionFlow(TransactionFlowOption.Allowed)] void ShowMessage(string msg); } Anyway, you should be aware of local tr

Categories : C#

How to sort after join and groupby
To order the items in the group, just call OrderBy: var query = from p in _productRepository.Table join ps in _productScheduleRepository.Table on p.Id equals ps.ProductId where ... group new{ p, ps } by p.Id into Grouped select Grouped.OrderBy(pair => pair.ps.end).FirstOrDefault().p;

Categories : C#

WCF call working when Fiddler On, else gives 400 Bad Request while debugging
Checking the cert. There are potentially two client certificates. The one used on the TLS session and the one used in the SAML Token/SOAP message. Typically they are the same cert. But added by different parts of the code. Fiddler only knows about the TLS cert. If you had to add the TLS client cert to fiddler, then it could be this indeed. Test is simple, remove it from the Fiddler directory. If i

Categories : C#

Image click in C# WinForms Browser Control
Not all images in html has the type attribute. So you must define such that your clickable image has. For example, I redacted your code: Initialisation of the webBrowser (you can put it in the constructor of your WinForm): webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted); webBrowser1.Navigate("http://www.google.com"); Your

Categories : C#

Is it OK to slowly give back data from a webserver in this way?
I think the more conventional approach is to poll the server using javascript. This approach is also used and called a long poll. This document will be helpful if you are hosting in IIS. I would like to point out it recommends against long running tasks. http://blogs.msdn.com/b/tmarq/archive/2010/04/14/performing-asynchronous-work-or-tasks-in-asp-net-applications.aspx "In case you're curious,

Categories : C#

Simplify queries on two tables with identical structures
You won't get them much simpler than that other than perhaps using a union and then sorting it out in memory, but the code will be ugly. You have a pretty clean way of doing it there, bearing in mind that the schema of the tables does differ slightly. The only optimisation I would recommend is instead of doing a .Count()==0, try using .Any(). That will translate to an 'Exists' in SQL, which is

Categories : C#

Get filename from URL with php header location
You could simply check the HttpWebResponse.Headers when downloading the file, they should contain the headers you sent along. I guess an example you could use is this one, i adapted it a bit for your specific usage (nl: the filename that you need to get) using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; namespace wget {

Categories : C#

Extracting List from complex type
You want Maps = itinerary.ItineraryDays.Select(id => id.Listing.Port.Maps).ToList(); If Listing.Port.Maps is a single object. If it is a collection then you'll want SelectMany.

Categories : C#

C# lambda syntax
In this example, Lambdas are like methods. This is a roughly equivalent code: private SomeMethod(List<string> s) { Assert.IsNotNull(s); Assert.AreEqual(1, s.Count); } clientSearchAsync("Getting", SomeMethod, Assert.IsNull); In a nutshell, you're passing SomeMethod to SearchAsync method as a parameter, and SearhAsync invokes it in its body.

Categories : C#

how to reorder worksheet positions in C#
You need to use the Position property. Try adding ws.Position = 1; here is the reference: https://closedxml.codeplex.com/wikipage?title=Organizing%20Sheets&referringTitle=Documentation

Categories : C#

C# pointer / reference
b does not point to a, no, b points to the object referenced by a at the time of the assignment. Changes in the variable a will not be observable through b. Changes to the object referenced by a will be observable to b. There are ways to reference a (the variable, not the value it references) though. One being a lambda: Func<Dog> c = () => a; Whenever c is invoked, it will return t

Categories : C#

Cannot Convert Implicit Types
The method you are calling is returning an array of 'TriggerAnim' objects. You would need either public TriggerAnim[] Instance = GetComponentsChildren<TriggerAnim>(); or // This would select the First TriggerAnim object depending on some condition you must specify public TriggerAnim Instance = GetComponentsChildren<TriggerAnim>().First( x = > ...); What you choose would depen

Categories : C#

How left join in select union in linq c#?
Left Outer Join sample. var sample= (from e in table1 join d in table2 on e.column equals d.column into ej from d in ej.DefaultIfEmpty() select new {e.column , e.column , d.column });

Categories : C#

ASP.NET-MVC serve files in a directory as if they were in root
Okey, so, as always, the guaranteed way to encounter the answer in the next 5 minutes is to finally ask the question on SO. The answer is IIS URL Rewrite Module. Found the info on it here You need to add this to your Web.config (the regexp still needs some work to shield the API route and add all possible symbols) <system.webServer> <rewrite> <rules> <ru

Categories : C#

Calculate Percent Increase and Decrease
You're way over thinking it. double CalculateChange(long previous, long current) { if (previous == 0) throw new InvalidOperationException(); var change = current - previous; return (double)change / previous; } To display this data to a user in a friendly 'percentage' format, you can use: string DoubleToPercentageString(double d) { return "%" + (Math.Round(d, 2) * 100).

Categories : C#

Crystal Reports and WPF handling record selection and parameter
Found the answer. Turns out that r1.DataDefinition.RecordSelectionFormula = rs; was over writing the the reports record selection. Adding this fixed it if (rs != "") { rs = r1.DataDefinition.RecordSelectionFormula + " and " + rs; } else { rs = r1.DataDefinition.RecordSelectionFormula; }

Categories : C#

How to access MSMQ in C# behind load balancer (F5)
There is no MSMQ aware load balancer. F5 also cannot achieve that for direct queuing to servers. Since MSMQ works with multiple ports for its communication back and forth. You can try the http option of MSMQ. That can be Network Load Balanced and communicates with single port. NserviceBus has Nservicebus.Gateway which simplifies this solution. You can also use Distributor from Nservicebus to loa

Categories : C#

Limit input of user one per session per item
let's understand the meaning of your suggestions: using a session: you are opening a session key at your server and map a list of id's which already had commented. you can match a specific product against this session and determine if the product can be commented or not. pros: very elegant and easy to maintence solution cons: a user which request your website (say from another browser) will be

Categories : C#

Why Parallel.For gives only so little gain for this particular function?
After playing around with your example some, I conclude that the bulk of the disparity in timing you're seeing is due to GC overhead, with initialization overhead in both scenarios being high enough to make performance differences relatively unimportant even once the GC overhead is removed from the test. When I switch the order of the tests, the parallel one winds up faster than the non-parallel

Categories : C#

Where are navigation elements declared in default Web Forms template?
It's probably coming from a Master Page. Look at the <%@ Page %> header at the tops of the .aspx files. You'll see they reference a master page. A Master Page is used to provide structure to the site. It means you don't have to write the same HTML for common elements on every single content page. Content pages (.aspx) then can have their content inserted into the Master Page. And yes, you ca

Categories : C#

Data annotation [Remote] doesn't exist in MVC 5?
The [Remote] attribute is in the System.Web.Mvc assembly. You need to include that in your using statements in order to use the [Remote] attribute. Here is the MSDN page referencing the [Remote] attribute as well for your reading.

Categories : C#

Accessing C# Static variable within a UnityScript
You need to put the C# files in the Standard Assets folder so they are compiled before the UnityScript files.

Categories : C#


Recently Add
How to call a method in .cs file which was implemented in code behind?
How To Prevent $variables In Restangular Post Request
Windows Phone 8 VoIP SIP Provider
How do we set the AutoCAD layer viewport override values
Load Dependent DLL using reflection
The code is not showing any error but still not displaying data on the datagrid of webform.?
Make an Image that can be flipped over in Unity 4.6
Storing JSON REST response in object
which is more efficient in conditional looping?
WebBrowser control's shortcut keys are not working
C# SQL INSERT not appearing in database table "no errors or exceptions thrown"
c# winfrom treeview class binding
How to Convert string "00h:03m:30s:793ms" to TimeSpan in c#
Calling a parameterized Stored Procedure that returns a value in C#
How to use the SQL statement to transform the data from row record to column record
How to Instantiate Enemy Prefabs Without Knowing the Name
MVC JQuery unobtrusive validation
How to draw at top left of metaFile
How to make Aggregate Root method only accessible for a Domain Event and nothing else.
how to create a list of lists from one list using LINQ?
Ignore user roles in ASP .Net MVC 5 Identity
Xpath Web scrape
add property to interface
How can I make controls added to existing mark-up be automatically hooked up to the code behind?
Too much data in C# windows form combobox, taking 30 sec to show the windows form
Creating a scrolling grid of images using WPF and XAML
PHP equivalent to asp.net routing
LINQ aggregate query
Custom Control won't fill dock correctly
Get ASP.NET Identity Current User In View
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.