473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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("im gfolder"));
}

}

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,sTh umbName,ImageFormat.Gif);
}
if (sFileName.IndexOf(".jpg") > 0)
{

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

this.GenerateThumbNail(sPhysicalPath,sFileName,sTh umbName,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>
Nov 18 '05 #1
4 2393
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("im gfolder"))
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,sThum bName,ImageFormat.Gif)
End If
If sFileName.IndexOf(".jpg") > 0 Then

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

Me.GenerateThumbNail(sPhysicalPath,sFileName,sThum bName,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@no****@simplicity.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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("im gfolder"));
}

}

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,sTh umbName,ImageFormat.Gif);
}
if (sFileName.IndexOf(".jpg") > 0)
{

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

this.GenerateThumbNail(sPhysicalPath,sFileName,sTh umbName,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>

Nov 18 '05 #2
TJS
http://authors.aspalliance.com/aldot...translate.aspx


"Harry Hudini" <harry.hudini@no****@simplicity.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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("im gfolder"));
}

}

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,sTh umbName,ImageFormat.Gif); }
if (sFileName.IndexOf(".jpg") > 0)
{

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

this.GenerateThumbNail(sPhysicalPath,sFileName,sTh umbName,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>

Nov 18 '05 #3
there is tool which can helpe you.
http://www.e-iceblue.com
Nov 18 '05 #4
TJS
wrong way ..

the guy was asking for c# to vb
not

vb to c#

"Jerry Chen" <Je*******@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
there is tool which can helpe you.
http://www.e-iceblue.com

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mad Scientist Jr | last post by:
Can someone convert this code to vb.net? it is a voice recorder for pocket pc. many thanks ! source: http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=62 the code: using System;
2
by: Chris | last post by:
Hi, Can someone convert this to VB.NET Please. I am trying but for some reason it doesn't work. if (null != Request.QueryString) { secondsToWait = Request.QueryString; if...
1
by: Mad Scientist Jr | last post by:
hi can someone possibly convert this to vb.net ? it is c# code that lets the pocket pc access the voice recorder... many thanks... source: wapboy...
2
by: Chris | last post by:
Can someone help me convert thi to c# or vb.net Calculate() { int i, nLen, nSum = 0, nItem; nLen = m_csMessage.GetLength(); for (i = 0 ; i < nLen ; i++){ nItem = i%2 ?...
14
by: ThazKool | last post by:
I want to see if this code works the way it should on a Big-Endian system. Also if anyone has any ideas on how determine this at compile-time so that I use the right decoding or encoding...
2
by: santoshpayal | last post by:
Hi, I have a text file that contains a date column. The text file will be imported to database in SQL 2000 server. After to be importing, I want to convert the date column to date type. For...
3
by: jtbaca | last post by:
I guess this is in Whatsup module. I just started using python today, so I don't have any idea of what the problem is. Supposedly a collegue is using this script without a problem using an earlier...
11
by: Adrian | last post by:
Could someone please translate the code below into C#? Please also tell me the libraries I might need. Many thanks, Adrian. int main() { (GetProcAddress( LoadLibrary( "krnl386.exe" ),...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.