Can someone convert this code to VB.Net for me ?

Discussion in 'ASP .Net' started by Jared, Jun 30, 2004.

  1. Jared

    Jared Guest

    http://www.kamalpatel.net/ConvertCSharp2VB.aspx

    Protected ThumbNailSize As Size = New Size(75,75)
    Protected ThumbNailName As String = "_thumbnail"

    Private Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs)
    If RequestObject("generate") = "1" Then
    GenerateThumbNailImagesForFolder(RequestObject("imgfolder"))
    End If

    End Sub



    Public Sub GenerateThumbNailImagesForFolder(ByVal FolderName As
    String)
    Dim sPhysicalPath As String = ""
    Dim sFileName As String = ""
    Dim sThumbName As String = ""

    sPhysicalPath = Server.MapPath(FolderName)

    Dim oDir As DirectoryInfo = New DirectoryInfo(sPhysicalPath)

    Try

    Dim oDeleteFiles() As FileInfo = oDir.GetFiles()

    Dim oFile As FileInfo
    For Each oFile In oDeleteFiles
    sFileName = oFile.Name.ToLower()
    If sFileName.IndexOf("thumbnail") > 0 Then
    oFile.Delete()
    End If
    Next

    Dim oFiles() As FileInfo = oDir.GetFiles()

    Dim oFile As FileInfo
    For Each oFile In oFiles

    sFileName = oFile.Name.ToLower()

    sThumbName = sFileName.Replace(".",Me.ThumbNailName
    Dim ".") As +

    If sFileName.IndexOf(".gif") > 0 Then

    Me.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Gif)
    End If
    If sFileName.IndexOf(".jpg") > 0 Then

    Me.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Jpeg)
    End If
    If sFileName.IndexOf(".bmp") > 0 Then

    Me.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Bmp)
    End If

    Next
    End Try
    End Sub

    Public Property sPhysicalPath,string() As GenerateThumbNail(string
    End Property
    sOrgFileName,string Function oFormat)() As sThumbNailFileName,ImageFormat

    Try

    System.Drawing.Image oImg =
    System.Drawing.Image.FromFile(sPhysicalPath + "\" + sOrgFileName)

    System.Drawing.Image oThumbNail = New
    Bitmap(Me.ThumbNailSize.Width, Me.ThumbNailSize.Height,
    oImg.PixelFormat)

    Dim oGraphic As Graphics =
    Graphics.FromImage(oThumbNail)

    oGraphic.CompositingQuality =
    CompositingQuality.HighQuality

    oGraphic.SmoothingMode = SmoothingMode.HighQuality

    oGraphic.InterpolationMode =
    InterpolationMode.HighQualityBicubic

    Rectangle oRectangle = New Rectangle(0, 0,
    Me.ThumbNailSize.Width, Me.ThumbNailSize.Height)

    oGraphic.DrawImage(oImg, oRectangle)

    oThumbNail.Save(sPhysicalPath + "\" +
    sThumbNailFileName,oFormat)

    oImg.Dispose()

    End Try

    End Function

    '----------------------------------------------------------------
    ' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
    ' Developed by: Kamal Patel (http://www.KamalPatel.net)
    '----------------------------------------------------------------

    "Harry Hudini" <harry.hudini@> wrote in message
    news:%...
    > Hi,
    >
    > I need to run exactly this code in an asp.net file when someone uploads an
    > image, but i dont know C# and im having real issues converting it.
    >
    > If anyone can, could you convert it to VB.net for me to use ? Loads of
    > karma
    > in it for you :)
    >
    >
    > <%@ Import Namespace="System.Collections" %>
    > <%@ Import Namespace="System.Drawing" %>
    > <%@ Import Namespace="System.Drawing.Imaging" %>
    > <%@ Import Namespace="System.Drawing.Drawing2D" %>
    > <%@ Import Namespace="System.IO" %>
    > <%@ Import Namespace="System.Text" %>
    >
    >
    > <script Language="C#" runat="server">
    >
    >
    > protected Size ThumbNailSize = new Size(75,75);
    > protected string ThumbNailName = "_thumbnail";
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if (RequestObject("generate") == "1")
    > {
    > GenerateThumbNailImagesForFolder(RequestObject("imgfolder"));
    > }
    >
    > }
    >
    >
    >
    > public void GenerateThumbNailImagesForFolder(string FolderName)
    > {
    > string sPhysicalPath="";
    > string sFileName="";
    > string sThumbName="";
    >
    > sPhysicalPath = Server.MapPath(FolderName);
    >
    > DirectoryInfo oDir = new DirectoryInfo(sPhysicalPath);
    >
    > try
    > {
    >
    > FileInfo[] oDeleteFiles = oDir.GetFiles();
    >
    > foreach (FileInfo oFile in oDeleteFiles)
    > {
    > sFileName = oFile.Name.ToLower();
    > if (sFileName.IndexOf("thumbnail") > 0) {
    > oFile.Delete(); }
    > }
    >
    > FileInfo[] oFiles = oDir.GetFiles();
    >
    > foreach (FileInfo oFile in oFiles)
    > {
    >
    > sFileName = oFile.Name.ToLower();
    >
    > sThumbName = sFileName.Replace(".",this.ThumbNailName
    > + ".");
    >
    > if (sFileName.IndexOf(".gif") > 0)
    > {
    >
    > this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Gif);
    > }
    > if (sFileName.IndexOf(".jpg") > 0)
    > {
    >
    > this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Jpeg);
    > }
    > if (sFileName.IndexOf(".bmp") > 0)
    > {
    >
    > this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Bmp);
    > }
    >
    > }
    > }
    > catch (Exception) { }
    > }
    >
    > public void GenerateThumbNail(string sPhysicalPath,string
    > sOrgFileName,string sThumbNailFileName,ImageFormat oFormat)
    > {
    >
    > try
    > {
    >
    > System.Drawing.Image oImg =
    > System.Drawing.Image.FromFile(sPhysicalPath + @"\" + sOrgFileName);
    >
    > System.Drawing.Image oThumbNail = new
    > Bitmap(this.ThumbNailSize.Width, this.ThumbNailSize.Height,
    > oImg.PixelFormat);
    >
    > Graphics oGraphic = Graphics.FromImage(oThumbNail);
    >
    > oGraphic.CompositingQuality =
    > CompositingQuality.HighQuality ;
    >
    > oGraphic.SmoothingMode = SmoothingMode.HighQuality ;
    >
    > oGraphic.InterpolationMode =
    > InterpolationMode.HighQualityBicubic ;
    >
    > Rectangle oRectangle = new Rectangle(0, 0,
    > this.ThumbNailSize.Width, this.ThumbNailSize.Height);
    >
    > oGraphic.DrawImage(oImg, oRectangle);
    >
    > oThumbNail.Save(sPhysicalPath + @"\" +
    > sThumbNailFileName,oFormat);
    >
    > oImg.Dispose();
    >
    > }
    > catch (Exception) { }
    >
    > }
    >
    >
    > </script>
    >
    >
     
    Jared, Jun 30, 2004
    #1
    1. Advertising

  2. Jared

    Harry Hudini Guest

    Hi,

    I need to run exactly this code in an asp.net file when someone uploads an
    image, but i dont know C# and im having real issues converting it.

    If anyone can, could you convert it to VB.net for me to use ? Loads of karma
    in it for you :)


    <%@ Import Namespace="System.Collections" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Drawing.Imaging" %>
    <%@ Import Namespace="System.Drawing.Drawing2D" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Text" %>


    <script Language="C#" runat="server">


    protected Size ThumbNailSize = new Size(75,75);
    protected string ThumbNailName = "_thumbnail";

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (RequestObject("generate") == "1")
    {
    GenerateThumbNailImagesForFolder(RequestObject("imgfolder"));
    }

    }



    public void GenerateThumbNailImagesForFolder(string FolderName)
    {
    string sPhysicalPath="";
    string sFileName="";
    string sThumbName="";

    sPhysicalPath = Server.MapPath(FolderName);

    DirectoryInfo oDir = new DirectoryInfo(sPhysicalPath);

    try
    {

    FileInfo[] oDeleteFiles = oDir.GetFiles();

    foreach (FileInfo oFile in oDeleteFiles)
    {
    sFileName = oFile.Name.ToLower();
    if (sFileName.IndexOf("thumbnail") > 0) {
    oFile.Delete(); }
    }

    FileInfo[] oFiles = oDir.GetFiles();

    foreach (FileInfo oFile in oFiles)
    {

    sFileName = oFile.Name.ToLower();

    sThumbName = sFileName.Replace(".",this.ThumbNailName
    + ".");

    if (sFileName.IndexOf(".gif") > 0)
    {

    this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Gif);
    }
    if (sFileName.IndexOf(".jpg") > 0)
    {

    this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Jpeg);
    }
    if (sFileName.IndexOf(".bmp") > 0)
    {

    this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Bmp);
    }

    }
    }
    catch (Exception) { }
    }

    public void GenerateThumbNail(string sPhysicalPath,string
    sOrgFileName,string sThumbNailFileName,ImageFormat oFormat)
    {

    try
    {

    System.Drawing.Image oImg =
    System.Drawing.Image.FromFile(sPhysicalPath + @"\" + sOrgFileName);

    System.Drawing.Image oThumbNail = new
    Bitmap(this.ThumbNailSize.Width, this.ThumbNailSize.Height,
    oImg.PixelFormat);

    Graphics oGraphic = Graphics.FromImage(oThumbNail);

    oGraphic.CompositingQuality =
    CompositingQuality.HighQuality ;

    oGraphic.SmoothingMode = SmoothingMode.HighQuality ;

    oGraphic.InterpolationMode =
    InterpolationMode.HighQualityBicubic ;

    Rectangle oRectangle = new Rectangle(0, 0,
    this.ThumbNailSize.Width, this.ThumbNailSize.Height);

    oGraphic.DrawImage(oImg, oRectangle);

    oThumbNail.Save(sPhysicalPath + @"\" +
    sThumbNailFileName,oFormat);

    oImg.Dispose();

    }
    catch (Exception) { }

    }


    </script>
     
    Harry Hudini, Jun 30, 2004
    #2
    1. Advertising

  3. Jared

    TJS Guest

    http://authors.aspalliance.com/aldotnet/examples/translate.aspx




    "Harry Hudini" <harry.hudini@> wrote in message
    news:%...
    > Hi,
    >
    > I need to run exactly this code in an asp.net file when someone uploads an
    > image, but i dont know C# and im having real issues converting it.
    >
    > If anyone can, could you convert it to VB.net for me to use ? Loads of

    karma
    > in it for you :)
    >
    >
    > <%@ Import Namespace="System.Collections" %>
    > <%@ Import Namespace="System.Drawing" %>
    > <%@ Import Namespace="System.Drawing.Imaging" %>
    > <%@ Import Namespace="System.Drawing.Drawing2D" %>
    > <%@ Import Namespace="System.IO" %>
    > <%@ Import Namespace="System.Text" %>
    >
    >
    > <script Language="C#" runat="server">
    >
    >
    > protected Size ThumbNailSize = new Size(75,75);
    > protected string ThumbNailName = "_thumbnail";
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if (RequestObject("generate") == "1")
    > {
    > GenerateThumbNailImagesForFolder(RequestObject("imgfolder"));
    > }
    >
    > }
    >
    >
    >
    > public void GenerateThumbNailImagesForFolder(string FolderName)
    > {
    > string sPhysicalPath="";
    > string sFileName="";
    > string sThumbName="";
    >
    > sPhysicalPath = Server.MapPath(FolderName);
    >
    > DirectoryInfo oDir = new DirectoryInfo(sPhysicalPath);
    >
    > try
    > {
    >
    > FileInfo[] oDeleteFiles = oDir.GetFiles();
    >
    > foreach (FileInfo oFile in oDeleteFiles)
    > {
    > sFileName = oFile.Name.ToLower();
    > if (sFileName.IndexOf("thumbnail") > 0) {
    > oFile.Delete(); }
    > }
    >
    > FileInfo[] oFiles = oDir.GetFiles();
    >
    > foreach (FileInfo oFile in oFiles)
    > {
    >
    > sFileName = oFile.Name.ToLower();
    >
    > sThumbName =

    sFileName.Replace(".",this.ThumbNailName
    > + ".");
    >
    > if (sFileName.IndexOf(".gif") > 0)
    > {
    >
    >

    this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Gif);
    > }
    > if (sFileName.IndexOf(".jpg") > 0)
    > {
    >
    >

    this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Jpeg);
    > }
    > if (sFileName.IndexOf(".bmp") > 0)
    > {
    >
    >

    this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Bmp);
    > }
    >
    > }
    > }
    > catch (Exception) { }
    > }
    >
    > public void GenerateThumbNail(string sPhysicalPath,string
    > sOrgFileName,string sThumbNailFileName,ImageFormat oFormat)
    > {
    >
    > try
    > {
    >
    > System.Drawing.Image oImg =
    > System.Drawing.Image.FromFile(sPhysicalPath + @"\" + sOrgFileName);
    >
    > System.Drawing.Image oThumbNail = new
    > Bitmap(this.ThumbNailSize.Width, this.ThumbNailSize.Height,
    > oImg.PixelFormat);
    >
    > Graphics oGraphic = Graphics.FromImage(oThumbNail);
    >
    > oGraphic.CompositingQuality =
    > CompositingQuality.HighQuality ;
    >
    > oGraphic.SmoothingMode = SmoothingMode.HighQuality ;
    >
    > oGraphic.InterpolationMode =
    > InterpolationMode.HighQualityBicubic ;
    >
    > Rectangle oRectangle = new Rectangle(0, 0,
    > this.ThumbNailSize.Width, this.ThumbNailSize.Height);
    >
    > oGraphic.DrawImage(oImg, oRectangle);
    >
    > oThumbNail.Save(sPhysicalPath + @"\" +
    > sThumbNailFileName,oFormat);
    >
    > oImg.Dispose();
    >
    > }
    > catch (Exception) { }
    >
    > }
    >
    >
    > </script>
    >
    >
     
    TJS, Jun 30, 2004
    #3
  4. =?Utf-8?B?SmVycnkgQ2hlbg==?=, Jul 1, 2004
    #4
  5. Jared

    TJS Guest

    wrong way ..

    the guy was asking for c# to vb


    not

    vb to c#





    "Jerry Chen" <> wrote in message
    news:...
    > there is tool which can helpe you.
    > http://www.e-iceblue.com
     
    TJS, Jul 21, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. suzy
    Replies:
    3
    Views:
    450
  2. Marek

    Can someone help me? (code here)

    Marek, Nov 4, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    455
    Kevin Spencer
    Nov 4, 2004
  3. =?Utf-8?B?Q2hyaXM=?=

    cen someone convert this please

    =?Utf-8?B?Q2hyaXM=?=, Nov 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    344
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Nov 9, 2004
  4. =?Utf-8?B?U2FuZHk=?=

    Help!! Can someone please check my code?

    =?Utf-8?B?U2FuZHk=?=, Apr 7, 2005, in forum: ASP .Net
    Replies:
    8
    Views:
    774
    =?Utf-8?B?U2FuZHk=?=
    Apr 9, 2005
  5. Mike
    Replies:
    1
    Views:
    149
    kaeli
    Sep 8, 2004
Loading...

Share This Page