C#
This is pretty much a no brainer for code. However I went and looked and everything I found was either overkill, or i wasn't certain of the internals so i had to say run it, look at the properties etc.
So I wrote a simple app to do it and put it on codeplex at:
http://setfiledate.codeplex.com/
This problem stemmed from the fact that I got this weird DVD player and I needed it to play some files from a USB stick in a loop. It loops fine, the problem was ordering. No clue how the ordering was. I thought it might be one...
apparently you can use a transaction scope for this and just wrap everything that way. but to me that seems more complicated than just enabling it with execute command. some LINQ code like (note that ‘this’ is a data context): this.ExecuteCommand("set transaction isolation level read uncommitted"); MyTable.Take(5).Dump(); Produces this sql code: set transaction isolation level read uncommitted GO SELECT TOP 5 <fieldnames…> FROM [MyTable] AS [t0] GO That’s what I want to see, so yay. =) some links:...
So today I needed to cross reference some stuff in a text file with some stuff in a db. No big deal. Had about 200 unique values to lookup a few pieces of info out of a larger table in a db. The target table had about a half million rows in it, but was indexed on this particular column I needed to lookup on so it seemed like it should be no big deal. I have found myself using LINQPad more and more for little ad-hoc stuff like this.
Anyway, I was prepared to do something similar to this:...
There are lots of ways to do things like this. Here's a pretty simple way with c# and .net. forgive some of the using shortcuts, i was just isolating a couple of areas. and as always i normally just post these so i don't forget =P
this is just a console app to add a single item to a task list in sharepoint. very simple. the only thing that was a bit of a pain is you need to find your sharepoint id for the person. the easiest way i found that for myself was simply to go to the list,...
so i needed to count the lines of a bunch of different filetypes in a folder. i decided to try using linq for this. here's what i came up with. basically a single linq statement =Pyou can tune the regex to taste. i just said (i think, i'm not a regex wizard) something that isn't a newline (.+) and the line terminators i'm using (\r\n). using System;using System.Collections;using System.IO;using System.Linq;using System.Text.RegularExpressions;namespace LineCounter{ class LineCounter { static void Main(string[] args) { // dir to search string d = @"c:\pathtocode"; // regex match for newlines string lf = @".+\r\n"; // get the...
Stack q = new Stack();q.Push(argument);while (q.Count > 0){ string d = q.Pop().ToString(); Console.WriteLine(d); foreach (string sd in Directory.GetDirectories(d)) q.Push(sd);}
Found something nifty I didn't know about today. create multiple objects in a single using statement. I figured i would include some sample code i use for compression/decompression. I'm using the #ziplib libraries, but you could use any stream based process really. The bufferSize variable you can change to fit your needs. //unzip data. assume we have a compressed file and are creating the output
file
using (FileStream
u = File.Create(PathToUncompressedFile),
c = File.OpenRead(PathToCompressedFile))
using (GZipInputStream gzip = new
GZipInputStream(c))
while
((bufferSize = gzip.Read(buffer, 0, buffer.Length)) != 0)
u.Write(buffer, 0, bufferSize);
//zip data. assume we have a uncompressed file and are creating the output
file
using (FileStream
u...
foreach (IPAddress ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList) Console.WriteLine(ip.ToString());
string sql = "some sql"ArrayList al = new ArrayList();using (SqlConnection cn = new SqlConnection(cs))using (SqlCommand cmd = new SqlCommand(sql, cn)) { cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) while (dr.Read()) { object[] o = new object[dr.FieldCount]; dr.GetValues(o); al.Add(o); }}foreach(object[] o in al) Console.WriteLine(a1(o[0].ToString());
this is a little unique of a setup. i'm having to update a varbin field, but the data that is coming in from the other sources is being cast from xml. so i'm sort of replicating the stupid thing we are doing on the other side, but it seems like a good code sample for this particular method. if you wanted to chunk up xml, you could use this method.
using (SqlConnection cn = new SqlConnection(cs))
{string staging_sql = @"
create table ##t (t varchar(max));
insert ##t select '';";
string load_sql = @"update ##t set t .write(@a,null,0)";string update_and_cleanup_sql = @"
update
tablewithvarbincolumn
set
varbincolumn =...
Full C# Archive