.net-4.0

Get leading whitespace

做~自己de王妃 提交于 2019-12-06 07:50:42
I just wrote this method and I'm wondering if something similar already exists in the framework? It just seems like one of those methods... If not, is there a better way to do it? /// <summary> /// Return the whitespace at the start of a line. /// </summary> /// <param name="trimToLowerTab">Round the number of spaces down to the nearest multiple of 4.</param> public string GetLeadingWhitespace(string line, bool trimToLowerTab = true) { int whitespace = 0; foreach (char ch in line) { if (ch != ' ') break; ++whitespace; } if (trimToLowerTab) whitespace -= whitespace % 4; return "".PadLeft

How to Host WCF REST Service and WCF Data Service in the same global.asax

冷暖自知 提交于 2019-12-06 07:35:06
问题 I have a WCF REST web service that is hosted via a service route in global.asax which looks like this; protected override void RegisterRoutes(System.Web.Routing.RouteCollection routeTable) { routeTable.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(UserService))); } I am wondering whether or not it is possible to also host another web service (which is a WCF Data Service) in the same application. protected override void RegisterRoutes(System.Web.Routing.RouteCollection

MVC3 publishing and IIS 6

房东的猫 提交于 2019-12-06 07:33:17
I've been fighting with this for several hours with no headway. I am trying to publish a web app (MVC3, .net4, made in Visual Studio 2010) to a server. All googles eventually lead to this article , which has not been helpful. According to it, MVC3 running on IIS 6 (MVC and .net4 are installed, it is a 2k3 server) should just work. Different set ups give me different issues, but nothing that works. With default settings, I get "Directory Listing Denied This Virtual Directory does not allow contents to be listed." If I turn on directory browsing I can see the directoy of the site, but this isn't

How to handle report viewer session expired exception

て烟熏妆下的殇ゞ 提交于 2019-12-06 07:28:11
问题 I have the following situation: Microsoft Report Viewer 2010 is used to display reports (.rdlc files) in local mode in an ASP.NET web application. The report data is supplied by assigning a datasource in the code behind of an ASPX page. Here's an example: if(!IsPostBack){ ReportViewer1.Reset(); ReportDataSource reportDataSource = new ReportDataSource(); reportDataSource.Name = "DataContainerType"; reportDataSource.Value = DatasourceOnPage; reportDataSource.DataSourceId = "DatasourceOnPageID";

WinForm ComboBox add text “Select” after data binding

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 07:25:26
At my form, I have one control ComboBox. I want after databinding add text "Select". I try this cbOperatorList.DataSource = operatorService.GetOperatorList(); cbOperatorList.Items.Insert(0, "Select"); But when I do this. I get exception what Changing the collection of items is impossible if you set the property DataSource. UPDATE public BindingList<Operator> GetOperatorList(string filter = "") { return new BindingList<Operator>( this.operatorRepository.All.Where( item => item.FirtsName.Contains(filter) || item.LastName.Contains(filter) || item.MiddleName.Contains(filter)). ToList()); } UPDATE

Application deployment to network drive

﹥>﹥吖頭↗ 提交于 2019-12-06 07:14:12
问题 I have a .NET 4 WPF application that needs to run inside a company network. The application does not use local files (it does have an app.config file but it only contains some connection strings ) for data storage but a central SQL server database. What are the downsides of putting the application files on a shared network drive and just creating a shortcut to the application executable for each user? I've found some data on the subject in the following links but I couldn't get a clear answer

How to get the maximum outbound requests when parellellizing asynchronous calls?

北战南征 提交于 2019-12-06 06:41:32
Analysing the code below in action through Fiddler, I realized that using Parallel Extensions I can get at maximum 2 outbound requests: new string[] { "http://stackoverflow.com", "http://superuser.com", "http://serverfault.com", "http://stackexchange.com" } .AsParallel() .Select(a => HttpWebRequest.Create(a).GetResponse()) .ToArray() ; What method should I use to maximize the number of outbound requests? This code runs all 6 HTTP requests in parallel on my machine according to Wireshark: var urls = new string[] { "http://stackoverflow.com", "http://superuser.com", "http://serverfault.com",

TcpClient communication with server to keep alive connection in c#?

和自甴很熟 提交于 2019-12-06 06:13:23
问题 I've this TcpClient code which works fine. It connects to perl server on linux system and receives anything that server sents to it. Works nicely. public static void Main() { foreach (ProtocolConnection tcpConnection in TcpConnectionsList) { ProtocolConnection connection = tcpConnection; ThreadPool.QueueUserWorkItem(_ => { ThreadTcpClient(connection); ManualResetEventTcp.Set(); }); } ... Some code... } public static void TcpConnect(ProtocolConnection varConnection) { int retryCountSeconds =

DateTime supported language for formatting?

一曲冷凌霜 提交于 2019-12-06 06:04:05
DateTime let you format depending of the current culture. What are the culture supported by default? The scenario I have in mind use this.Date.Value.ToString("MMMM") which will print "January" if the culture is set to english-us but will print "Janvier" if the culture is in french-ca. This formatting documentation can be found at MSDN website but doesn't give the scope of culture this one can translate. I would like to know what languages are supported and if a language is not, what are my options? You can use CultureInfo.GetCultures to get all supported cultures. CultureInfo[] cultures =

Silverlight 4 Assembly Sharing Problem

南笙酒味 提交于 2019-12-06 05:48:56
问题 I have a WPF .NET 4.0 class library referencing a Silverlight 4 class library. The SL library compiles fine but when I compile the WPF class library, I get: Error 2 Unknown build error, 'Cannot resolve dependency to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.' MyProj