PlausiblyDamp
Administrators-
Posts
7016 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by PlausiblyDamp
-
Certain areas of the file system are protected under vista and if you need to write to those areas then you will need to mark the application as requiring administrator privileges, easiest way of doing this is by providing a manifest for your application similar to the one found here. This way you will be automatically prompted to elevate your permissions as soon as the application runs. Before doing this though it might be worth considering if you really do need to write to these parts of the file system - what does your application do that needs to write outside of a user's part of the system?
-
The easiest way of doing the 1st part is to expose the information from the user control as one or more properties, this way they can be accessed from the containing page. As to doing it the other way round that would be a bit more complicated - what kind of information would the control need to know about the page it is on?
-
What code are you using to remove the backslashes as there is no reason why this should fail. Dim s as string = "ssdfdsf\sdfsdfdsf" s=s.Replace("\"," ") string s = "dsfsdf\\fdsfsdf"; s = s.Replace('\\',' '); either should work.
-
Re: Handles is just a concise AddHandler Just tried it and it turns out you can actually remove an event handler that was attached using the Handles keyword! counter-intuitive doesn't even come close :)
-
SQL Server 2005 Error Handling vs C# Error handling
PlausiblyDamp replied to teixeira's topic in Database / XML / Reporting
Within your stored proc you can just use the RAISERROR command - the error will be passed up to .Net as long as you aren't clearing the @@error variable anywhere in your SQL code. Once the error hits .Net it will be a SqlException you can handle with a normal try ... catch block. -
The Handles statement only works for things that are declared at design time and you always want the handler to be associated with the event. AddHandler (and it's friend RemoveHandler) allow you to control this at run time and even add event handles to instances that are created during the program's execution.
-
Finding which programs access the internet
PlausiblyDamp replied to mrthingtome's topic in Water Cooler
http://www.microsoft.com/technet/sysinternals/Networking/TcpView.mspx is a good tool for this, and it's free! -
SQL Server 2005 Error Handling vs C# Error handling
PlausiblyDamp replied to teixeira's topic in Database / XML / Reporting
Rather than any absolute rules I find this tends to be a case of use what works best in a given situation... I am (currently anyway - the new Linq-SQL stuff could very well change my mind) a big fan of doing as much of the data access as possible within stored procedures on the database; this pretty much means I would be using the BEGIN TRY ... END TRY stuff on the SQL end for as much error handling as possible. Similarly I try to keep as much of the transactional stuff within the stored procedures as well, very rarely do I find myself using the .BeginTransaction method within .Net. In terms of how I handle errors I take pretty much the same approach as I would with .Net code; if the stored proc can catch and handle the error then there is no need to pass the error back and SQL can swallow the error. If the SQL error isn't something that can be safely handled / can be handled but the error needs to be passed up then I will get the stored proc to do as much of the error handling as makes sense but will then either re-throw the original error or raise a new application specific error that I an then trap within the .Net side of things. Note that I use these as a guideline rather than fixed rules - some situations may require things to be done differently (performance, security, required behaviour can all influence this) but I try to stick to these ideas as much as possible. -
When you are using web applications threading is not an easy option - as your .Net code is running on the server there is no way for it to control how a client browser handles multiple threads. Probably the easiest option is to look at the AJAX Toolkit as this will allow you to use javascript on the client to talk to server side code with a fairly minimal amount of effort.
-
I'm in desperate need of help - Form designer gives me an error!
PlausiblyDamp replied to EFileTahi-A's topic in General
I have seen this mentioned in a few places - one fix suggests turning off indexing for your project's folder (not a clue why this would fix the problem but some claim it does). Another suggestion is a corrupt resx file for a given form - using the resgen.exe you can convert the .resx to a .resources file and remove the existing.resx then try to open the form in the designer again, if it opens close it down and use resgen.exe again to convert the .resources back to a .resx file... -
It looks as though there is some COM stuff going on behind the scenes when accessing the clipboard - one of the issues you need to be careful with is different threading models and how COM copes (or not) with them. When you know though the fix is easy... change the button click event in your form1 to the following and it should work. private void button1_Click(object sender, EventArgs e) { ParameterizedThreadStart p = new ParameterizedThreadStart(Run); Thread t = new Thread(p); t.SetApartmentState(ApartmentState.STA);//set the correct threading model and all is good. t.Start(new Form2()); }
-
DefaultView Sort not sorting rows...
PlausiblyDamp replied to forgottensoul's topic in Database / XML / Reporting
Have you tried using the DataView object as the data source and as the variable you iterate over rather than it's table property? e.g. DataView tmp = myData.Tables["ATable"].DefaultView; tmp.Sort = "SomeColumn"; dataGridView1.DataSource = tmp; // Loop through each row in the tmp var. They are not sorted, // but the data grid is. foreach (DataRow currentRow in tmp) { string rowCol1 = currentRow[1].ToString(); } -
What is the "best" way to compress FileStream?
PlausiblyDamp replied to JumpyNET's topic in Directory / File IO / Registry
Looking at the classes under the System.IO.Compression namespace and as far as I can see neither the Defalte or the GZip streams give any means to set the compression level. http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx provide a free compression library that does expose the compression level however and is just as easy to use... e.g. the following is a simple cut and paste of the same routine Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim st As String Dim sr As New System.IO.StreamReader("c:\setupapi.log.0.old") st = sr.ReadToEnd() Dim fs As New System.IO.FileStream("c:\test1.bin", IO.FileMode.Create) Dim s As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter Dim Compresser As New System.IO.Compression.GZipStream(fs, IO.Compression.CompressionMode.Compress, False) s.Serialize(Compresser, st) Compresser.Close() fs.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim st As String Dim sr As New System.IO.StreamReader("c:\setupapi.log.0.old") st = sr.ReadToEnd() Dim fs As New System.IO.FileStream("c:\test2.bin", IO.FileMode.Create) Dim s As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter Dim Compresser As New ICSharpCode.SharpZipLib.GZip.GZipOutputStream(fs) Compresser.SetLevel(9) s.Serialize(Compresser, st) Compresser.Close() fs.Close() End Sub the c:\setupapi.log.0.old file is a 4.5M text file found in my windows folder which using the built in GZip compressed to 590K, using the ICSharp library set to level 9 compression came out as 155K - a fairly impressive saving. Given the ease of use of the ICSharp library I would be tempted to go that route rather than saving an uncompressed stream and then using some other tool to compress it later. As an aside the file sizes you were getting are reflective of the fact that an uncompressed file has more redundancy than a 'partially compressed' file and can be compressed better. EDIT: just tried it with the ICSharp's BZip2 routine Dim Compresser As New ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(fs) and the resultant file is now only 124K -
Quick version using List(of ) instead of arrays Public Class Form1 Public ThisNeedsToBeStored As New List(Of OwnStructA) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ThisNeedsToBeStored.Add(New OwnStructA) ThisNeedsToBeStored(0).Aaaa = "Test" ThisNeedsToBeStored(0).Cccc.Add("Testing") ThisNeedsToBeStored(0).Dddd.Add(New OwnStructB) ThisNeedsToBeStored(0).Dddd(0).Cccc.Add("sdfdsfdsfsdf") Dim fs As New System.IO.FileStream("c:\test.txt", IO.FileMode.Create) Dim s As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter s.Serialize(fs, ThisNeedsToBeStored) fs.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim fs As New System.IO.FileStream("c:\test.txt", IO.FileMode.Open) Dim s As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter Dim x As List(Of OwnStructA) x = s.Deserialize(fs) fs.Close() End Sub End Class _ Public Class OwnStructB Public Aaaa As String Public Bbbb As Date Public Cccc As New List(Of String) End Class _ Public Class OwnStructA Public Aaaa As String Public Bbbb As Date Public Cccc As New List(Of String) Public Dddd As New List(Of OwnStructB) End Class The above is pretty much the quickest thing I could throw together, in practice I would probably tend to make the OwnStructA and OwnStructB more fully implemented classes (Properties, validation etc.) and probably also create a class for the ThisNeedsToBeStored that simply inherits List(Of OwnStructA) as well.
-
Arrays that contain arrays pose certain problems (structures can also have issues...) so you aren't doing yourself any favours here ;) What version of .Net are you using? If you are using .Net 2 or later then replacing the arrays with generic collections (e.g. List(of ...)) would make this a lot simpler. The articles at http://msdn.microsoft.com/msdnmag/issues/02/04/net/default.aspx and http://msdn.microsoft.com/msdnmag/issues/02/07/net/default.aspx are probably worth a read if you are looking at implementing your own custom serialisation mechanism in .Net 1 though.
-
Been a while since I did anything programatically with FTP so I could be talking nonsense here... I think you will need to take the response to the PASV command and open another FTP connection to the server using the new information - if you still have the ftp server running PM me and I'll try to see if I can get it working tonight.
-
Downloading a file where the name isn't known?
PlausiblyDamp replied to mooman_fl's topic in Network
You will probably need to parse the underlying html e.g. the link you posted is [highlight=html4strict] http://files.modthesims2.com/getfile.php?file=522374 [/highlight] This could have given the file name as part of the mark-up though e.g. [highlight=html4strict] Filename.txt [/highlight] so depending on how the application is getting the information e.g. parsing the entire page would really limit how much information you would have to work with. -
http://articles.techrepublic.com.com/5100-3513-6131225.html looks like it might be useful.
-
Calling unmanaged c++ dll with c#
PlausiblyDamp replied to Pious's topic in Interoperation / Office Integration
Have you tried changing the CallingConvention e.g. DllImport("trdp.dll", SetLastError = true, CallingConvention=CallingConvention.StdCall) or whatever calling convention the DLL uses (my C knowledge is getting rusty...) -
Calling unmanaged c++ dll with c#
PlausiblyDamp replied to Pious's topic in Interoperation / Office Integration
IIRC 1008 as an error is permission related - what permissions does your user have and where are you running the app from? -
Are there any firewalls or proxy servers between the internet and the FTP server? If so they will need to be configured to allow traffic in through port 2100 as well.
-
Calling unmanaged c++ dll with c#
PlausiblyDamp replied to Pious's topic in Interoperation / Office Integration
You might try specifying the first parameter as string rather than a StringBuilder and see if that fixes the problem (it would be unusual to expect a native C / C++ routine to have any knowledge of the StringBuilder class). Similarly StringBuilder lpszServerName = new StringBuilder("127.0.0.1"); //would be better as string lpszServerName = "127.0.0.1"; -
If the objects are so different they can't have a consistent interface then you are always going to encounter problems in this kind of situation. Personally though I would still define relevant Interface(s) where possible and use it (them) rather than just using object as a datatype, if you need to access properties not defined in the interface then you would still need to cast the variable to the correct type - but at least the cast wouldn't be required in as many places.
-
Re: Upload File via FTP (URI is invalid for this FTP command) What version of .Net are you using? Also how is the variable FTPCon declared / defined?
-
COM DLL Import at design time
PlausiblyDamp replied to ADO DOT NET's topic in Interoperation / Office Integration
DLLImport is used to reference a normal (i.e. non COM) DLL and would be no help in this case. You should only be experiencing this problem when you attempt to use[/use] the component - simply running a program that references it will not be enough to cause a crash. Like I have said before simply wrap the call(s) to the component in a try catch block to catch the errors.