locked
C# to VB conversion problems RRS feed

  • Question

  • User1093848917 posted

     I am trying to convert http://www.codeproject.com/aspnet/FlashUpload.asp to VB

     

    1    using System;
    2    using System.Data;
    3    using System.Configuration;
    4    using System.Web;
    5    using System.Web.Security;
    6    using System.Web.UI;
    7    using System.Web.UI.WebControls;
    8    using System.Web.UI.WebControls.WebParts;
    9    using System.Web.UI.HtmlControls;
    10   using System.IO;
    11   
    12   public class Upload : IHttpHandler, IReadOnlySessionState
    13   {
    14       public Upload()
    15       {
    16       }
    17   
    18       #region IHttpHandler Members
    19   
    20       public bool IsReusable
    21       {
    22           get { return true; }
    23       }
    24   
    25       public void ProcessRequest(HttpContext context)
    26       {              
    27           if (context.Request.Files.Count > 0)
    28           {
    29               // get the applications path
    30               string tempFile = context.Request.PhysicalApplicationPath;
    31               // loop through all the uploaded files
    32               for(int j = 0; j < context.Request.Files.Count; j++)
    33               {
    34                   // get the current file
    35                   HttpPostedFile uploadFile = context.Request.Files[j];
    36                   // if there was a file uploded
    37                   if (uploadFile.ContentLength > 0)
    38                   {
    39                       uploadFile.SaveAs(tempFile + "client\\uploaded\\" + uploadFile.FileName);
    40                       // use this if using flash to upload
    41                                       
    42                   }                
    43               }
    44           }
    45           // Used as a fix for a bug in mac flash player that makes the 
    46           // onComplete event not fire
    47           HttpContext.Current.Response.Write(" ");
    48       }
    49   
    50       #endregion
    51   }
    

      After using some online tools and a bit of guesswork I have 2 problems at the moment:

    1) #region IHttpHandler Members       -  have no idea on this bit, get a "string constant expected" error
    2) Implements IHttpHandler             - gives the error
    BC30154: Class 'Upload' must implement 'ReadOnly Property IsReusable() As Boolean' for interface 'System.Web.IHttpHandler'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers.

     

    Cheers 

    Sunday, June 24, 2007 6:31 AM

Answers

  • User2032526919 posted

    Something like

     

    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    Imports System.IO
    
    Public Class Upload
        Implements IHttpHandler, IReadOnlySessionState
    
    #Region "IHttpHandler Members"
    
        Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
            Get
                Return True
            End Get
        End Property
    
        Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
            If context.Request.Files.Count > 0 Then
                ' get the applications path
                Dim tempFile As String = context.Request.PhysicalApplicationPath
    
                ' loop through all the uploaded files
                For i As Integer = 0 To context.Request.Files.Count - 1
                    ' get the current file
                    Dim uploadFile As HttpPostedFile = context.Request.Files(i)
                    ' if there was a file uploded
                    If uploadFile.ContentLength > 0 Then
    
                        uploadFile.SaveAs(tempFile + "client\\uploaded\\" + uploadFile.FileName)
                        '// use this if using flash to upload
    
                    End If
    
                Next
    
            End If
    
            ' Used as a fix for a bug in mac flash player that makes the 
            ' onComplete event not fire
            context.Response.Write(" ")
    
        End Sub
    #End Region
    End Class
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2007 7:07 AM
  • User397347636 posted

    Teemu got it almost spot on.

    Just 2 things missed: the constructor and the string literal left in extra back slashes.

    Here's the Instant VB translation:

     

    	Imports System
    	Imports System.Data
    	Imports System.Configuration
    	Imports System.Web
    	Imports System.Web.Security
    	Imports System.Web.UI
    	Imports System.Web.UI.WebControls
    	Imports System.Web.UI.WebControls.WebParts
    	Imports System.Web.UI.HtmlControls
    	Imports System.IO
    
    	Public Class Upload
    		Implements IHttpHandler, IReadOnlySessionState
    		Public Sub New()
    		End Sub
    
    		#Region "IHttpHandler Members"
    
    		Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    			Get
    				Return True
    			End Get
    		End Property
    
    		Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    			If context.Request.Files.Count > 0 Then
    				' get the applications path
    				Dim tempFile As String = context.Request.PhysicalApplicationPath
    				' loop through all the uploaded files
    				For j As Integer = 0 To context.Request.Files.Count - 1
    					' get the current file
    					Dim uploadFile As HttpPostedFile = context.Request.Files(j)
    					' if there was a file uploded
    					If uploadFile.ContentLength > 0 Then
    						uploadFile.SaveAs(tempFile & "client\uploaded\" & uploadFile.FileName)
    						' use this if using flash to upload
    
    					End If
    				Next j
    			End If
    			' Used as a fix for a bug in mac flash player that makes the 
    			' onComplete event not fire
    			HttpContext.Current.Response.Write(" ")
    		End Sub
    
    		#End Region
    	End Class
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2007 10:14 AM
  • User1425124765 posted

    use the following website

    http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2007 10:27 AM

All replies

  • User2032526919 posted

    Something like

     

    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    Imports System.IO
    
    Public Class Upload
        Implements IHttpHandler, IReadOnlySessionState
    
    #Region "IHttpHandler Members"
    
        Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
            Get
                Return True
            End Get
        End Property
    
        Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
            If context.Request.Files.Count > 0 Then
                ' get the applications path
                Dim tempFile As String = context.Request.PhysicalApplicationPath
    
                ' loop through all the uploaded files
                For i As Integer = 0 To context.Request.Files.Count - 1
                    ' get the current file
                    Dim uploadFile As HttpPostedFile = context.Request.Files(i)
                    ' if there was a file uploded
                    If uploadFile.ContentLength > 0 Then
    
                        uploadFile.SaveAs(tempFile + "client\\uploaded\\" + uploadFile.FileName)
                        '// use this if using flash to upload
    
                    End If
    
                Next
    
            End If
    
            ' Used as a fix for a bug in mac flash player that makes the 
            ' onComplete event not fire
            context.Response.Write(" ")
    
        End Sub
    #End Region
    End Class
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2007 7:07 AM
  • User397347636 posted

    Teemu got it almost spot on.

    Just 2 things missed: the constructor and the string literal left in extra back slashes.

    Here's the Instant VB translation:

     

    	Imports System
    	Imports System.Data
    	Imports System.Configuration
    	Imports System.Web
    	Imports System.Web.Security
    	Imports System.Web.UI
    	Imports System.Web.UI.WebControls
    	Imports System.Web.UI.WebControls.WebParts
    	Imports System.Web.UI.HtmlControls
    	Imports System.IO
    
    	Public Class Upload
    		Implements IHttpHandler, IReadOnlySessionState
    		Public Sub New()
    		End Sub
    
    		#Region "IHttpHandler Members"
    
    		Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    			Get
    				Return True
    			End Get
    		End Property
    
    		Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    			If context.Request.Files.Count > 0 Then
    				' get the applications path
    				Dim tempFile As String = context.Request.PhysicalApplicationPath
    				' loop through all the uploaded files
    				For j As Integer = 0 To context.Request.Files.Count - 1
    					' get the current file
    					Dim uploadFile As HttpPostedFile = context.Request.Files(j)
    					' if there was a file uploded
    					If uploadFile.ContentLength > 0 Then
    						uploadFile.SaveAs(tempFile & "client\uploaded\" & uploadFile.FileName)
    						' use this if using flash to upload
    
    					End If
    				Next j
    			End If
    			' Used as a fix for a bug in mac flash player that makes the 
    			' onComplete event not fire
    			HttpContext.Current.Response.Write(" ")
    		End Sub
    
    		#End Region
    	End Class
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2007 10:14 AM
  • User1425124765 posted

    use the following website

    http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2007 10:27 AM
  • User397347636 posted

    Unless you want it converted correctly...

    That online converter does a decent job sometimes, but for this sample it makes numerous mistakes:

    1. Doesn't use quotes for the #Region directive.

    2. Omits the "Implements" clauses.

    3. Closes the regions with "#endregion", which VB will not understand.

     

    Sunday, June 24, 2007 10:41 AM