.net-4.0

Convert a relative path that includes a drive letter to an absolute path for .NET file functions

风流意气都作罢 提交于 2019-12-04 15:49:50
问题 How can you convert a drive relative path such as D:test.xml into an absolute path that a function such as XDocument.Load() will accept. The D drive could have D:\data as its current working directory, for example, so D:test.xml would mean D:\data\test.xml . I've already tried such concoctions as D:.\test.xml . Here is the error I get for something like D:test.xml: Invalid URI: A Dos path must be rooted, for example, 'c:\' 回答1: You could use GetFullPath. For example: // should return "D:\data

IEnumerable not enumerating in foreach

断了今生、忘了曾经 提交于 2019-12-04 15:46:08
I'm encountering a problem with one of my IEnumerable 's that I haven't seen before. I have a collection: IEnumerable<IDependency> dependencies; that's being used in a foreach loop. foreach (var dependency in dependencies) For some reason this foreach doesn't iterate over my IEnumerable and simply skips to the end. If I change my foreach to loop through a a list however it seems to work fine: foreach (var dependency in dependencies.ToList()) What could I be doing that's causing this behaviour? I haven't experienced this with IEnumerable before. Update : Here's the entire code of my foreach

Formatting a string with string.Format(“{0:00}”

帅比萌擦擦* 提交于 2019-12-04 15:33:32
问题 I have just taken over some code and I see this used a lot. It seems to take the integer and create a string looking like "01", "02" etc. What I am not sure of is the convention used here. Why is the format {0:00} and not {00} ? string.Format("{0:00}", int.Parse(testVal) + 1); 回答1: The first 0 is the placeholder, means the first parameter. 00 is an actual format. For example it could be like this: var result = string.Format("{0:00} - {1:00}", 5, 6); result will be 05 - 06 . So the first 0 is

How to implement a Timeout on WebClient.DownloadFileAsync

我只是一个虾纸丫 提交于 2019-12-04 15:28:47
So I thought Webclient.DownloadFileAysnc would have a default timeout but looking around the documentation I cannot find anything about it anywhere so I'm guessing it doesn't. I am trying to download a file from the internet like so: using (WebClient wc = new WebClient()) { wc.DownloadProgressChanged += ((sender, args) => { IndividualProgress = args.ProgressPercentage; }); wc.DownloadFileCompleted += ((sender, args) => { if (args.Error == null) { if (!args.Cancelled) { File.Move(filePath, Path.ChangeExtension(filePath, ".jpg")); } mr.Set(); } else { ex = args.Error; mr.Set(); } }); wc

Behaviour of List<T>.Sort in .NET 4.5 changed from .NET 4.0?

本小妞迷上赌 提交于 2019-12-04 15:18:54
问题 I have the following test inside a project targeting .NET 4.0: [TestFixture] public class Donkey { [Test] public void TestListSorting() { var expected = new[] { MockRepository.GenerateStub<IComparable>(), MockRepository.GenerateStub<IComparable>() }; var sorted = new List<IComparable>(expected); CollectionAssert.AreEqual(expected, sorted); sorted.Sort(); CollectionAssert.AreEqual(expected, sorted); } } If I run it on a machine with only .NET 4.0 installed, it fails. If I run it on a machine

wpf datagrid bug? when toggle visibility on a column with an image as headercontent

久未见 提交于 2019-12-04 13:53:04
i have the following problem. if i use an image for a datagrid header i get an error while toggling visibility. <DataGridTextColumn Header="{StaticResource Image_Link}" IsReadOnly="True"> Error: Bei dem angegebenen Element handelt es sich bereits um das logische untergeordnete Element eines anderen Elements. the only workaround i found so far is to create a ControlTemplate with the specific image foreach of my imageheadercolumns. is this datagrid behaviour a bug? EDIT: Error translated by google: The specified element is already the logical child of another element. EDIT: Sample <Window x

Nested Resource Dictionary in separate library

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 13:52:16
问题 My question is very similar to this one I have a solution with a number of projects. The are two that are relevant: a class library that contains a WPF window and a project with all the WPF styles in it. Class Library with the window in Project 1 The Window's merged dictionary is something like: <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/StyleAssembly;component/CommonStyle.xaml"/> </ResourceDictionary.MergedDictionaries> //other styles here The

Application deployment to network drive

删除回忆录丶 提交于 2019-12-04 13:46:24
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: Run a .NET program from a mapped drive or shared folder - Pros/Cons Run a .NET program from a mapped

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

依然范特西╮ 提交于 2019-12-04 13:26:54
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 routeTable) { routeTable.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(UserService))); routeTable

Watch another application and if it closes close my app (without polling) c#

≡放荡痞女 提交于 2019-12-04 13:26:12
hi I want to "hook" another application so when it closes I can close my application. I don't want to poll the running process as this seems unnecessarily intensive, if I want to respond in real-time. I believe apps send out message within windows when they are created or closed etc how can I hook this to know when it closes? for example lets say my app loads checks running processes to ensure notepad is loaded and if so it remains loaded until notepad is closed. as notepad is closed my app some how knows this and exits... is this possible if so how? it needs to work on xp vista and win7 If