|
just pass it in like anything else
<br />
string[] files = System.IO.Directory.GetFiles(@"c:\");<br />
writeFileList(files);<br />
<br />
void writeFileList(string[] names)<br />
{<br />
foreach(string name in names)<br />
{<br />
System.Console.WriteLine(name);<br />
}<br />
}<br />
<br />
<br />
hth
Al
|
|
|
|
|
I am trying to retrieve the last modified date of an external webpage. I have found numerous ways to do this in vb, java, etc... but not in C#.
Heres some of them:
VB - http://www.freevbcode.com/ShowCode.asp?ID=362
ASP (so basically the same thing) - http://www.webdeveloper.com/forum/archive/index.php/t-3706.html
I've tried using HTTPWebRequest and HTTPWebResponse, since HTTPWebResposne has a LastModified property, but this is when the response was last modified, not the page. So I'm stuck... Any help would be awesome
--Peter
|
|
|
|
|
You can call Response.GetResponseHeader("Last-Modified") to get the time, but then you have to parse it -- and there's about 3 standard time formats in HTTP. Luckily I wrote a parser for a web server[^] a while ago, so here it is:
static DateTime ParseHttpTime(string str)
{
DateTime dt;
try
{
dt = DateTime.ParseExact(str, httpDateTimeFormats, System.Globalization.DateTimeFormatInfo.InvariantInfo,
System.Globalization.DateTimeStyles.AllowWhiteSpaces | System.Globalization.DateTimeStyles.AdjustToUniversal);
}
catch(FormatException)
{
dt = DateTime.Parse(str, CultureInfo.InvariantCulture);
}
return dt;
}
The method can throw an ArgumentNullException if the input is null and a FormatException if the input isn't formatted properly.
Keep in mind this happens a lot... most servers don't seem to return a Last-Modified value these days.
|
|
|
|
|
So if the server doesen't return a Last-Modified value, as you said most servers don't these days, then is it still possible to retrieve the Last-Modified date of a page via some other means? Or am i just out of luck?
--Peter
|
|
|
|
|
I can't think of any other ways...
|
|
|
|
|
For some reason, every day or two, Visual Studio 2005 changes one instance of the word 'Component' to 'UserControl' (or to 'Form') in my .csproj file. I'm not sure why this happens. If I accept the change, within a few days, it gets changed back by Visual Studio.
Does anybody understand what is causing this problem? I can't seem to figure it out why this is happening. It just switches back and forth between 'Component' and 'UserControl'. It's kind of annoying because source control keeps wanting me to check out/save the changes to the file.
Thanks in advance for your help,
Curtis
|
|
|
|
|
Sounds like a bug... my guess is that it's because in WPF, custom controls are called UserControls. I personally think the name Component makes more sense, but bleh.
I think the MSDN Feedback Center[^] is where you want to look.
|
|
|
|
|
Hello,
I will be working with large data sets (> 4Gb) of binary data and was wondering if anyone was aware a method of reading an XML that I am thinking of embedding in the binary with XmlTextReader().
Thanks in advance for any help and have a good weekend
|
|
|
|
|
kevin-rf wrote: I will be working with large data sets (> 4Gb) of binary data
The person that designed that DB should be shot, repeatedly.
|
|
|
|
|
>> I will be working with large data sets (> 4Gb) of binary data
>The person that designed that DB should be shot, repeatedly.
Not a DB application, reading large real world data at high speeds (2 - 5 Mhz) for extended periods. The goal of embedding the XML is to tag some of the parameters used in the data acquisition setup. The thought is XML would be more flexible than a fixed binary header that is very "version" dependant. Data will later be crunched off line into chewable morsels.
The goal is to be able to pull the XML out and make some of the after the fact presentation/processing decisions based upon the XML parameters.
|
|
|
|
|
Ok, maybe I was bit harsh, I was reading XML and Dataset (the class).
IMO it would be easier just to define some C struct and fread it, XML has no real benefit for binary data.
|
|
|
|
|
Well you could Base64 encode data and shove it in an XML, but leppie's right, that wouldn't be a good idea, even with the benefit of extensibility. 4gb of data in XML can get huge.
Your best bet would probably be to sit down and think the file format over on the byte scale keeping in mind all the ways you might possibly need to use it, and then write a reader/writer for it.
|
|
|
|
|
A fair amount of the structuring of the file has been thought out. I am trying to evaluate how to store some of the nondescript data that does not directly effect readout of the binary but would be nice to include with the file. Stuff like the lab bench is green, So and So had to stand on there head spitting nickles to get the test to work, the nickle rate was 2.3 a second.
Embedding binary data in XML is not optimal for two reasons.
1. Encoding Binary Data increases the storage foot print.
2. Encoding the Data is slower than just streaming the data to a HardDrive.
The actual storage of the data will be done in unmanaged C++ for speed (Other side of the cube wall). My goal is to process the data after the fact in C#. The processing is not a CPU intensive, so C# will work nicely. One of the things I am trying to evaluate is, if an XML was tacked into the binary (The structure being defined will support inclusion) how do I get it back. The question is does anyone know of a way to pull the XML out of the binary and dump it into something such as XMLTextReader().
Is there an easy way to generate your XML in memory and then feed it to XMLReader() for parsing?
Thankyou for your feedback...
|
|
|
|
|
You could use XmlDocument. Save the document in the file with a particular encoding (UTF8 is good), note down its size, and then when you load it again, read those bytes and use System.Text.Encoding.Decode to get the xml string back, which you'd read using XmlDocument.Load().
By the way, C# can be as good or better performing than C++ (maybe not more if you consider the fact that C++ can do assembly), believe it or not, even for nitty gritty stuff like this.
Try using C# with pointers; that way you won't have to put the code in a separate assembly. Just make an array of sequential structs and drain all the data in.
|
|
|
|
|
Hello all,
I'm doing a project that does a lot of dynamic inspection of assemblies. Does anyone know of a quick, clean way to save a reference to an assembly within code? In other words, I need some way to persist the information required to locate an assembly so I can load it again later. It's easy enough when it is in the GAC, but what do I do when I want to allow the user to load an assembly from a configurable directory. Any thoughts?
Thanks,
Will
|
|
|
|
|
I think you can do System.IO.Path.GetDirectory(assembly.Location), and then determine the relative path of the file to the configurable directory. You'd probably have to write some code to walk through the subdirectories.
So if the directory is c:\someapp\assemblies and you have an assembly in c:\someapp\assemblies\mammals\dog.dll, the reference would be recorded as mammals\dog.dll.
Just an idea.
|
|
|
|
|
Ok, I've searched my MSDN documentation, but to no avail.
I seem to remember from a different language (whether from C++ or Java, I'm not sure, but I'm leaning toward Java) that, with a two-dimensional array, I could initialize one row at a time, kinda sorta like this:
<br />
someType[][] arrayName = new someType[#][#];<br />
arrayName[0] = new someType[#];<br />
(note syntax of second line!)
Is there a way, in C#, to handle one ROW of a two-dimensional array (as if it were a single-dimensional array)?
I'm aware that the [][] syntax isn't used in C# (I'm aware of the fact that C# instead uses commas in one set of []). But, you get what I'm saying, right?
-Daniel
Typing too fast fro my owngood
-- modified at 16:49 Friday 19th May, 2006
|
|
|
|
|
The [][] syntax is used in C# to create a jagged array (where each sub-array can have a different length). It sounds like that is what you should use.
Josh
|
|
|
|
|
Really? I'll try it again. Thanks!
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
I've created a CharArray that includes alpha characters and Numbers.
For Example the array might look like this:
[a][b][c][1][2][3]
I want to be able to check if each array is a character or an integer. If it's a character I want to assign it an equivelent number I assign.
For example in the first case of [a] I want to check if it's a character. Since it is, I want to assign a's with the number 1. So it will replace [a] with [1]. If it later checks [2] I want it to see that it's an integer and to leave the value at [2].
So my end result might look like this:
[1][2][3][1][2][3]
Any help on this would be appreciated. Sorry for the "noob" questions I have been posting but I am trying to learn Thanks!
|
|
|
|
|
I would recommend using Int32.TryParse (if you don't want to use Int32.Parse with a try/catch block). That's how I'd do it.
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
TryParse is only available in 2.0 (OP didn't specify whether which version they are using).
Since you're only dealing with single characters, the way I'd do it is to use char.IsDigit and char.IsApha to determine if you're dealing an integer or a character, then do the appropriate conversion.
-----
In the land of the blind, the one eyed man is king.
-- modified at 17:01 Friday 19th May, 2006
|
|
|
|
|
The simplest form of the code.
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public string PrintXML()
{
// Create a WebBrowser instance.
WebBrowser webBrowserForPrinting = new WebBrowser();
return "Success";
}
}
Hello world works ok.
PrintXML fails with an exception of the form:
System.Threading.ThreadStateException: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
at System.Windows.Forms.WebBrowser..ctor()
at Service.PrintXML()
Can anyone give me hints on what to do with this?
I've tried using attribute [STAThread] to make the method single threaded but it seems to be getting ignored.
I'm at a loss as to how to instantiate a browser control in a web service. I need to do this so I can send HTML to a printer on the same box as the web service that runs.
thanks!
|
|
|
|
|
Well, AFAIK, IIS doesn't run in single-threaded apartment. You'll have to create another application that can run in single-threaded apartment and make a remoting call to it. For instance, try writing a console app or windows service and have your web method call that. I was wondering if you could create a new AppDomain with a different apartment threading model, but it doesn't look like that's possible.
www.logifusion.com
|
|
|
|
|
That sounds like a workable idea but I dont know how to make a call on an external app from a web service (or from any other windows code for that matter) I'm from linux/java/c and doing these things in windows, I just dont know how yet.
Anyone shed any light on how to make a call out to an external app from a web service?
Thanks!
|
|
|
|