Jump to content
Xtreme .Net Talk

inzo21

Avatar/Signature
  • Posts

    76
  • Joined

  • Last visited

Everything posted by inzo21

  1. Hi there. Thank god for beer! The current predicament of the week is as follows: I have two assemblies in a single solution, A and B. Assembly A is an application that installs a context menu into the file system (like that Winzip Icon when you right click on a file). When a user clicks on one of the options to that function, such as "Add this file!", a new object of assembly is instantiated and the method AddFile(filename) is called - then the object is disposed. The AddFile method simply appends the name of the working file to a text file in the same directory as the calling assembly. If the file does not exist, it creates it. Here is the code I used to get the executing assembly: Private myassembly As System.Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly() Private tempfile As FileInfo = New FileInfo(myassembly.Location) Private m_filelist As String = tempfile.DirectoryName & "\FileList.txt" This works great when I compile and run it in V Studio . NEt. The context menu works and the text file gets created when not present. However...when I create an installation package and deploy the app, I'm not getting the anticipated result. Everything installs and all .dll's are copied to the program directory. The menu works fine - the only issue I have is that it is writing back to the directory where I compiled the original code for the context menu (assembly A) - as opposed to the application directory. Does anyone have an idea of why this would happen? When I isolate the Assembly B and call AddFile from a command line app, it works fine when deployed. The issue seems to be in the method I am calling or instantiating an object of class B from Assembly A. this kept me up many nights so any help would be much appreciated. Thanks in advance, inzo
  2. Still not working. Okay - I took a look at the article you suggested PDamp and got some things out of it. I came up with the following test mod - which still isn't functioning. Module Module1 Sub Main() Dim cryptoprovider As RijndaelManaged = New RijndaelManaged Dim key As Byte() = {11, 2, 7, 24, 16, 22, 4, 38, 27, 3, 11, 10, 17, 15, 6, 23} Dim iv As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} Dim xtw As XmlTextWriter Dim filename As String = "c:\testing\test.xml" Dim FileWriter As FileStream = New FileStream(filename, FileMode.Create) Dim CryptoWriter As CryptoStream = New CryptoStream(FileWriter, cryptoprovider.CreateEncryptor(key, iv), CryptoStreamMode.Write) xtw = New XmlTextWriter(CryptoWriter, System.Text.Encoding.UTF8) 'FileWriter.Close() Console.WriteLine("File Encrypted") Console.ReadLine() xtw.Close() Dim FileReader As FileStream = New FileStream(filename, FileMode.Open) Dim CryptoReader As CryptoStream = New CryptoStream(FileReader, cryptoprovider.CreateDecryptor(key, iv), CryptoStreamMode.Read) 'FileReader.Close() Dim XmlDoc As XmlDocument = New XmlDocument Dim XmlReader As XmlTextReader = New XmlTextReader(CryptoReader) Try XmlDoc.Load(XmlReader) Console.WriteLine("file..............") Console.WriteLine(XmlDoc.OuterXml.ToString) Console.ReadLine() Catch ex As XmlException Console.WriteLine(ex.ToString) Console.ReadLine() End Try End Sub End Module I get a system.xml.xmlexception - the root element is missing error. The file is being encrypted but it seems that either the decryption is not working or there is garbage going in there that I can't parse out. Any ideas? inzo
  3. Hello all, the predicament for the evening. I have a well formed xml file used for configuration in an application. I want to decrypt/encrypt this file when it gets used - thus when the app loads it decrypts and loads the contents in an xmldocument - when the app exists it encrypts and saves the contents back to the file. I figured this would involve the following pseudo-code. on app load 1. read file into a byte array 2. run byte array through class.decryptfunction - returns another byte array 3. read returned byte array into memory stream 4. serialize memorystream into well-formed xml doc 5. load memorystream into xmldocument object for processing without any encryption, I tried declaring an array of bytes and loading the contents of the xmldoc into this array. I then created a memorystream and read the contents of the byte array into that stream. I finally tried load the memorystram into the xmldocument. Try Dim mymem As MemoryStream = New MemoryStream Dim ar() As Byte = PrepFile(FileLocation) mymem.Write(ar, 0, ar.Length) Console.WriteLine("byte ar: " & mymem.Length) configfile.Load(mymem) Console.WriteLine(configfile.OuterXml) Catch e As Exception Console.WriteLine("Exception: {0}", e.ToString()) End Try the array and mem stream have data - but I receive an XMLException - root element missing. I'm guessing that this has something to do with serialization. Does anyone have any ideas how to accomplish this or can they point me to a good article or two. thanks, inzo
  4. Really weird Okay - on a whim, I tried adding a parameter to to the method so that in the web service it reads: public function getstring(s as string) as string s = s & "-test" return s end function I then call the proxy to this as dim proxy as myservice.myclass = new myservice.myclass proxy.getstring("client call") and it works. The only change was adding a parameter to the method call. Now I'm completely confused. Does anyone have any idea what is going on in the backend? inzo
  5. No soup! Hey VB... I tried your suggestions and I guess it seems to be a problem with the serialization. I placed option strict on, and attempted passing a string from the web service. In the client, I create a string object and make it equal the proxy.getstring() function from the web service. It compiles, but at runtime I get the following error: An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll Additional information: Cast from type 'XmlNode()' to type 'String' is not valid. I am able to call other functions and subroutines from the web service - but they are returned as byte arrays. At this point, I'm still not sure what I'm doing wrong. Do you think I need to serialize the string into xmla nd then deserialize it on the client end? thanks again for the help. I really need it as I learn this stuff. inzo
  6. Hello all, new problem of the day. I want to pass a list of string names in from a web service to a client. I have tried using both an array of strings, an arraylist, and a collection - all to no success. My preference is to use an arraylist for the iteration and array manipulation methods already built in. Here is the error I get: Additional information: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Collections.ArrayList may not be used in this context. On the service, I use the following code for testing. Public Function GetManifest() Dim tar As New ArrayList m_mancounter = 0 tar.Add("test") tar.Add("test2") Return tar End Function the client code reads: Public Sub GetAllFiles() 'Try Console.WriteLine("processing manifest") Dim availablefiles As Object Dim proxy As myservice.servmethods = New myservice.servmethods availablefiles = proxy.GetManifest Console.WriteLine("filecount: " & availablefiles.Count.ToString) If Not (availablefiles.Count = 0) Then For Each i As String In availablefiles Console.WriteLine("file: " & i) Next Else : Console.WriteLine("Array is Empty!") End If 'Catch ex As Exception 'End Try End Sub I declare an object rather than an arraylist based on an article I read here from VBAhole... I think ;-) Does anyone have any clue what I'm doing wrong or have any ideas on how I can send this info over without high bandwidth - i.e. no xml docs or class bojects? thanx in advance inzo
  7. got it! Okay - for all those reading. The httpruntime element that you can configure / set in the web.config file for web services, applies only towards uploads according to msdn. Thus I test this by doing a file transfer app that transfers to a web service that only accepts 1 mb files. In reverse, I was able to pull files larger than 1 mb (tested 30mb) off of the server byte copying a simple byte array from the web service to the client machine. just an fyi for everyone. inzo
  8. Hello all, I'm in the process of developing an app that transfers files to and from a file server via web services. I know that to use web services, you can either break the file up in chunks that are less then 4 MB or set the maxlength property. This is primary to protect against DOS attacks and help with the SOAP processing. Now, the question. Is this technique applicable only for incoming requests - i.e. posting to the file server web service. What I want to know is if I need to reverse the process when a uses wants to download a file from the file server? As the request would be getting a file, is there a way to allow downloads to be downloaded with having to break them up on the file server and reassemble them on the client? thanx in advance. inzo
  9. Hello all. I wrote an application that takes a file, encrypts it, compresses it, and splits it up for processing on a web server. The original design called for the splitting a file off of a memorystream - but I watch the memory usage spike up to about 100MB in the Task Manager. If I split the file off of an actual file, I get a much lower memory usage - about 60MB - but the processor utilization is higher by about 20 percent. It's an asynchronous app. This will be used for transferring files to and from a web server in a local network. My question: Which do you think is better - using more memory with a lower CPU rate or a higher CPU utilization but lower memory requirements. thanks for your thoughts. inzo
  10. Hello All, Okay - here is the dilemma. I am trying to transfer large data files via web services in a file transfer apaplication that is implemented over the internet. I have a client app that calls the file transfer method of eh web service and passes it a filename, directory to put the file in and an array of bytes represnting the file. I know that the default files size is about 4 MB and I changed the allowable size in web.config. But I don't want to open myself up to DOS attacks and such. Thus, I want to beable to break the file up and send chunks of data to the web service and then have it reassembled on the file server end where the web service sits. Once reassmebled, it save into the driectory specified. The key part, is that I want to do this asychronously so as to not maintain a session - although if I can't, I can't. I don't even know where to begin. I have the array of bytes - but I'm not sure how to both break that array down into a set size and then pass those chunks to a receiving method that reassmbles it. Does anyone have any code or pseduo-code they can offer to help me get started. I ahve reviewed the info on MSDN with their cold storage strategy - it wasn't that clear though. thanks in advance. inzo
  11. Got It! I love Microsoft!!! ;-) The issue seemed to be instantiating a directory object. When I isolated this with another web service, it had a hard time with the constructo - stating it was deemed private. I did some searching and found that I needed to call the operation outright. Thus, I replaced the directory check with the follwing code: If Not (Directory.Exists(fulldirpath)) Then Directory.CreateDirectory(fulldirpath) End If Dim fullpath As String = fulldirpath & "\" & filename works fine now. Thanks for the interest though Pdamp. You seem to always be around. inzo
  12. getting there Hey pDamp - I tried that. Thanks though. I've narrowed it down to the inability for it to create the directory. When I pulled out the following piece of code and hardcoded a directory to write the byte array to, it worked fine. Dim ds As Directory If ds.Exists(dirname) Then Debug.WriteLine("Dir Exists") Else ds.CreateDirectory(dirname) Debug.WriteLine("Directory Created!") End If still stuck on this. inzo
  13. Hello All, I'm trying to call a webmethod that accepts three parameters - a filename, a dirname, and an array of byte. The goal is to create the directory passed and transfer the file from client to server. Pretty straightforward. I'm testing on a WinXP Pro box with IIS 6. When I run my test module however, I get an error dealing with insuffucient access to write to the directory. However, the directory does get created - it just hangs when it tries to create the file and write the bytes to it. I have tried setting the code access permissions for the .Net framework (i.e. Admin tools - .Net Configuration - Machine - Local Intranet Zene and set the Permission set to full access and the membership condition to all code. Still the same error. Specifically, I get this error: An unhandled exception of type 'System.Web.Services.Protocols.SoapException' occurred in system.web.services.dll Additional information: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.UnauthorizedAccessException: Access to the path "testing" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.Directory.InternalCreateDirectory(String fullPath, String path) at System.IO.Directory.CreateDirectory(String path) at BTFileTransferApps.Service1.SaveThisFile(String filename, String dirname, Byte[] bytearray) in C:\Inetpub\wwwroot\BTFileTransferApps\FileWorks.asmx.vb:line 69 --- End of inner exception stack trace --- my web service call looks like this: <WebMethod()> _ Public Sub SaveThisFile(ByVal filename As String, ByVal dirname As String, ByVal bytearray As Byte()) Debug.WriteLine("process started from web...file: " & filename) Dim ds As Directory If ds.Exists(dirname) Then Debug.WriteLine("Dir Exists") Else ds.CreateDirectory(dirname) Debug.WriteLine("Directory Created!") End If Dim fullpath As String = "c:\servertest" & "\" & dirname & "\" & filename Debug.WriteLine("web - dir name: " & dirname) Debug.WriteLine("web - file name: " & filename) Debug.WriteLine("web - full name: " & fullpath) Debug.WriteLine("Attempting to save file!") Dim fsInput As FileStream = New FileStream(fullpath, FileMode.Create, FileAccess.Write) fsInput.SetLength(0) fsInput.Write(bytearray, 0, bytearray.Length) fsInput.Close() Debug.WriteLine("File created from Byte Array") End Sub anyone have any ideas. thanx, inzo
  14. if it's an identity, you can add an output parameter to the stored procedure declare ( @value ) increment you field here set @value = @@identity. the @@identity will return the last value generated automatically for the inserted record. If you are returning another feidl value other than an identity, the same method should work. inzo
  15. maybe...? I like your handle. Perhaps you can mount the network resource as a drive to the fileserver that you are trasnferring to and reference it via straight unc or file url? On the loop question, I noticed that in your loop, you are instantiating a new instance of yuour web service method for each item in your array. You might want to reconstruct the method and call a particular function of a single instance for every service in the ar5ray. I have a file transfer service that recursively scans directories and transfers files using this method. It's less garbage to clean up and a little more efficient. just an idea. inzo
  16. Check out BORDERS Hey there, I got a book the other day for 8 bucks - Database Programming with VB.Net. There is also 101 Visual Basic .Net applications and some good books by Wrox on web services. Most of them are in VB.Net. In short, learn how to authenticate to a database using a windows forms or command console and then wrap that code ina class. Compile that class and use it in your web service. After that, you can look into passing the information in the SOAP header and all of the other advanced stuff. :-) if you have something specific, post it and we can see what we can help with. good luck, inzo
  17. Hello all, I'm looking around for a control or wondering if I can easily create one that allows a user to view the contents of a directory in a web browser - but rather then a standard list of all items, view them with the typical icons and associations that they would see if they viewed them in windows explorer. I guess it's similiar to web dav technology. any ideas? inzo
  18. Hello all, I have the following situation. I have a user control embedded in a web form that has a panel on it. Within the panel, there are other multiple user controls with their initial visibility set to false. When the user clicks on a link in the web form, I want it to set the visibility to true for a prticular user control in the panel. This works fine. However, what I wanted to do is loop through all controls in the panel when the user clicks the linkbutton and set their visibility to off. I then locate the user control in question and set its visbility to on. This is where I'm having an issue. Here is the code I am using in the linkbutton, which is on the user control on the web form. Dim myuc As UserControl = New UserControl For Each myuc In Me.Controls myuc.Visible = False Next myuc myuc = Me.FindControl("ucsub_x22release") myuc.Visible = True The error I get is this: Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Line 57: Private Sub lnk_contactnds_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnk_contactnds.Click Line 58: Dim myuc As UserControl = New UserControl Line 59: For Each myuc In Me.Controls Line 60: myuc.Visible = False Line 61: Next myuc Source File: C:\Inetpub\wwwroot\xweb\corpinfo.ascx.vb Line: 59 Can anyone point me in the right direction on how to accomplish this? Thanx in advance, inzo
  19. how about... Hey there, I did something like this by use the XML DOM. I loaded the xml file into an xml document in memory. You can then parse the memory doc and see if nodes exist and, if they do, add and alter the document to your desire. Once the alterations are done, you call the save method of the document and it will overwrite the file with the new data. I'll see if I can find the source for this but you might want to check it out on MSDN - I think that's where I learned it from. inzo
  20. Hello All, I'm trying to encrypt the contents of a file directly to a memorystream and then return that stream from the function. Having some issues - mostly that no data actually goes into the memorystream. Here is the following code: Public Function EncryptFileToStream(ByVal filename As String) Try Dim fsInput As New FileStream(filename, FileMode.Open, FileAccess.Read) Dim inputData(CInt(fsInput.Length - 1)) As Byte fsInput.Read(inputData, 0, CInt(fsInput.Length)) fsInput.Close() Dim mystring As FileInfo = New FileInfo(filename) Console.WriteLine("File length: " & mystring.Length) Dim mstream As New MemoryStream(inputData.Length) mstream.SetLength(0) Console.WriteLine("Byte length: " & inputData.Length) Dim csEncrypted As New CryptoStream(mstream, crpSym.CreateEncryptor(m_key, m_iv), CryptoStreamMode.Write) csEncrypted.Write(inputData, 0, inputData.Length) csEncrypted.FlushFinalBlock() csEncrypted.Close() Console.WriteLine("File Stream Created!") Console.WriteLine("Stream length: " & mstream.Length) Return mstream Catch ex As Exception Return Nothing Console.WriteLine("File Encryption could not occur! Could not write to stream.") End Try End Function The string passed to the function is the path to the file and it is valid and exists. I am able to encrypt directly to a file - but need to do it to a stream and then return the memorystream - which will be read from another function and serialized into a file on a remote server. Anyone have any ideas as to why the mem stream contains no data after this. thanx in advance, inzo
  21. Hello all. ARRGGGHH! That's the word of the day! I have a web site that has three panels on it - each with one or more user controls. The menu panel on the top has a single control as does the links panel on the left side. The content panel on the right has multiple user controls that pull infor from various xml files. The issue. On the page load, I set the visibility of the user control (uc_home) to true - which is in the content panel. When the user clicks a button in the user control in the menu panel, I want it to alter the properties of the user controls in the content panel - particularly the visbility. I successfully did this with HTML img objects and javascript code. But I need to do it using the asp:linkbutton object and, I guess, code behind. Thus, I declared a property on the parent page and try to set that when the user control is selected. So if a user selects the linkbutton news, the property gets set to the value "news" which is then used in the PreRender method of the parent page to set the visibility of the uc_news control to true. It's not working. Here's the pertinent code for the parent page and the linkbutton. The contenttoload / ...tohide is used to load the new content and hide the previous content. These values are stored in session objects. <---parent page---> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then m_theuc = "proservices" '<- this is a member variable to hold uc value OldContent = m_theuc System.Diagnostics.Debug.WriteLine("from new: " & OldContent) StartTime = Now() Else End If End Sub Private Sub Page_PreRender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.PreRender ContentToLoad = CallUC System.Diagnostics.Debug.WriteLine("uc from render:" & CallUC) System.Diagnostics.Debug.WriteLine("old from render:" & OldContent) System.Diagnostics.Debug.WriteLine("load from render: " & ContentToLoad) Dim fullname As String = "uc_" & ContentToLoad Dim oldfullname As String = "uc_" & OldContent contenttohide = Me.FindControl(oldfullname) contenttohide.Visible = False contenttodisplay = Me.FindControl(fullname) contenttodisplay.Visible = True OldContent = ContentToLoad End Sub <---User Control---> Private Sub linknews_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles linknews.Click Dim test As xweb.index = New xweb.index test.CallUC = "news" End Sub any ideas?
  22. Got It! Thanks PDamp. That didn't work, however. The runtime had a problem calling the dispose method of the form class directly - and I didn't want to marshal the reference or anything. Thus, I came up with the following and added it to the exception catch: Dim pholder As Process = Process.GetCurrentProcess pholder.Kill() it kills the process of the current executing thread - just what I needed. I was attempting to terminate the application - which worked - but not the process that got started as a result of it. for those reading, you'll need to import system.serviceprocess to use this. thanx again, inzo
  23. Hey all, I'm trying to detect the presence of a specific windows service by name and I am not able to do so. Here is the code I'm using: btsched = New ServiceController("theservicename", ".") Try MsgBox("The theservicename is" & btsched.Status.ToString, 64, "Service Monitor") Catch ex As Exception MsgBox("The theservicename must be installed prior to starting BackTrack Monitor", MsgBoxStyle.Critical, "Service Monitor") Application.Exit() End Try I couldn't find a servicecontroller .exists method so I am testing the service in this try statement. The issue I have is that the application (which is a system tray application) does not exit upon the try clause exception. any ideas? thanx in advance, inzo
  24. Hey sj, Try to implement you're own dispose and finalize methods on the class. Make the class inherit idisposable and then implement a dispose method that closes any stream. Even though there is no close method on a FileInfo object, sometime it still gets stored in the heap until the garbage collector picks it up. It might be as simple as invoking the garbage collector automatically in the dispose method: Public Overloads Sub Dispose() Implements IDisposable.Dispose If DisposeCalled Then Return End If ' call your stream closures here GC.SuppressFinalize(Me) DisposeCalled = True End Sub hope this helps. inzo
  25. I agree with wess... use a session variable if you can and maintain the state across the entire site for the duration of the users visit. Either way, if you're on active directory or LDAP 2, you can possibly even query the login of the user for their group id and use that for access. inzo
×
×
  • Create New...