Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help converting small vb code to c#

Status
Not open for further replies.

cjtaylor

Programmer
Joined
Aug 12, 2001
Messages
69
Location
US
Hello,

I am learning c# and was wondering if anyone could help convert this small snippet of vb code to c#?

Dim blob() As Byte
Dim bvariant As Object

If RegTemplate Is Nothing Then
Exit Sub
End If

RegTemplate.Export(bvariant)

blob = bvariant
Kill("c:\template.fpt")
FileOpen(1, "c:\template.fpt", OpenMode.Binary)

FilePut(1, blob)
FileClose(1)

I having difficulty finding a method(or a way) comparable to what RegTemplate.Export(bvariant) does in vb, same with the FilePut method any help would be greatly appreciated.

 
Code:
string path = @"c:\template.fpt";
// Delete the file if it exists.
if (File.Exists(path)) 
{
    File.Delete(path);
}

//Open the stream and read a blob 
using (FileStream fs = File.OpenRead(@"c:\myblob.dat")); 
        {
            byte[] blob = new byte[1024];
            UTF8Encoding temp = new UTF8Encoding(true);
            while (fs.Read(b,0,b.Length) > 0) 
            {
                Console.WriteLine(temp.GetString(b));
            }
        }

FileStream fs = File.Create(path);
// Generate a blob from a string
string valBlob="This is a blob..."; 
byte[] blob = new UTF8Encoding(true).GetBytes(valBlob);
fs.Write(blob, 0, blob.Length);
fs.Close();
or
byte[] blob = new byte[1024]; 
// Fill here the blob array
fs.Write(blob,0,blob.Length);
fs.Close();
-obislavu-
 
Thanks for your help, my friend. Your time is greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top