BlueMercury

I am completely new to sharepoint. I am attempting to create a very basic webpart for a trial. When I write code in C# it works fine however when I write it in VB.net it does not show in the list to be imported. I have made several C# parts and imported them without and issue. I am installing the DLL to the GAC, adding the trusted assembly tag to the web.config file and all the C# parts show up to be imported but the VB.NET never shows on the list. Other than the code language I am using the exact same methods to get them into Sharepoint. Thanks in advance for any help.

C# Code:

using System;

using System.Collections.Generic;

using System.Web;

using System.Text;

namespace CSWebPart

{

public class CSWebPartTongue Tiedystem.Web.UI.WebControls.WebParts.WebPart

{

protected override void Render(System.Web.UI.HtmlTextWriter writer)

{

writer.Write("This is a webpart using C#");

base.Render(writer);

}

}

}

VB.NET Code:

Imports System

Imports System.Collections.Generic

Imports System.Text

Imports System.Web

Namespace VBWebPart

Public Class VBWebPart

Inherits System.Web.UI.WebControls.WebParts.WebPart

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

writer.Write("This is a webpart made using Visual Basic")

MyBase.Render(writer)

End Sub

End Class

End Namespace



Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

amishjt

Instead of using Sub in your code can you try using Function. Nothing else seems to be wrong.

Thanks,






Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

BlueMercury

Tried changing to Function but render method doesn't allow the change and code doesn't compile. Thanks



Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

BlueMercury

So is it even possible to develop weparts in vb.net and use them in Sharepoint



Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

Pritam Dahake

I have been experimenting with webparts, but havent had any luck to get the "Hello World" webpart to work in VB.net.

With C# there is no problem. Are there any VB.net developers out there who have done any webpart development for WSS 3.0

Here is the basic "Hello World" webpart in VB.net that I am trying to get it to work.

I created a Class Clibary project and added Microsoft.Sharepoint.dll as a reference.

Strong name created for assembly.

Copied the assembly to bin directory.

Safe entry added to web.config file.

Did an iisreset

When I go to the Web Part gallery and click "New" I do not see my webpart there.

Imports System.Web.UI

Imports Microsoft.SharePoint.WebPartPages

Namespace MyWebParts

Public Class HelloWorldPart

Inherits WebPart

Protected Overrides Sub RenderWebPart(ByVal writer As HtmlTextWriter)

writer.Write("hello world!")

End Sub

End Class

End Namespace





Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

Curtis Ruppe (MicroStaff IT)

Blue,

Are you using the 4-part naming convention in your SafeControl section Type="*" Are there any SafeControl entries that have Safe="false" Are you updating the correct web.config file Have you done iisreset, and all that mess. The VB.NET code is correct as is. Function is not valid for Render, as it does not return anything.

These are the things I would check.





Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

Cheryl Bearden

I am also having the same problem. Webparts work ok in c# but will not show up in the Web Part Gallery when coded in vb. I was finally able to get the webpart to show up in the Web Part Gallery by creating a *.webpart xml file and uploading it using the 'Upload' Button on the Web Part Gallery screen. However, then I was not able to view the vb web part on the Web Part Preview screen. The c# version previewed correctly.

I too am wondering if vb webparts will work with SharePoint.





Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

SoloHiker

Visual Basic (ASP.Net 2.0) webparts do work fine in Sharepoint; they're the only kind I build. Smile



Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

Pritam Dahake

Hi SoloHiker,

Can you please post the complete code for a HelloWorld vb.net SharePoint webpart

Thanks

-Pritam





Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

kennymxp

SoloHiker wrote:
Visual Basic (ASP.Net 2.0) webparts do work fine in Sharepoint; they're the only kind I build.
I also encouter the same problem. For example:
This super simple C# webpart will show itself in the Web Part Gallery : New Web Parts

using System.Web.UI.WebControls.WebParts;

using System.Web.UI;

namespace ClassLibrary1

{

public class Class1 : WebPart

{

public Class1()

{

this.ExportMode = WebPartExportMode.All;

}

protected override void Render(HtmlTextWriter writer)

{

writer.Write("A super simple WebPart using default class library template.");

}

}

}

However this simple (almost identical except for the name) VB webpart won't even I used the exact method to deploy it (signing, compile, put into GAC, add SafeControl to web.config, iisreset,...). Please help. Thanks.

Imports System.Web.UI.WebControls.WebParts

Imports System.Web.UI

Namespace ClassLibrary2

Public Class Class2

Inherits WebPart

Public Sub New()

Me.ExportMode = WebPartExportMode.All

End Sub

Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)

writer.Write("A super simple WebPart using default class library template.")

End Sub

End Class

End Namespace






Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

Cheryl Bearden

Hi Solohiker,

What version of Sharepoint are you using

Thanks,

Cheryl





Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

SoloHiker

Cheryl, I'm currently developing webparts for MOSS 2k7, but I've also built them for WSS 3.0.

Here's what a very simple "Hello, World!" looks like:

Code Snippet

Imports System

Imports System.Collections.Generic

Imports System.ComponentModel

Imports System.Text

Imports System.Web

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Reflection

<DefaultProperty("Text"), ToolboxData("<{0}:HelloWorld runat=server></{0}:HelloWorld>")> _

Public Class HelloWorld

Inherits System.Web.UI.WebControls.WebParts.WebPart

<Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property Text() As String

Get

Dim s As String = CStr(ViewState("Text"))

If s Is Nothing Then

Return String.Empty

Else

Return s

End If

End Get

Set(ByVal Value As String)

ViewState("Text") = Value

End Set

End Property

Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)

output.Write("Hello, World!")

End Sub

End Class





Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

Cheryl Bearden

Thanks very much SoloHiker for sharing your code. I kept comparing your code with the code from the 3 book examples that I've been trying to make work, to figure out what is keeping these examples from working. The only thing that I could find that made a difference was the 'Namespace' statement that existed in all of the book examples. (Visual Studio will give your assembly a root namespace if you leave the namespace out, so it isn't necessary to include one.) When I took the Namespace statement out the examples did work ok. What a strange bug. Thanks again for giving us something that actually worked!



Re: SharePoint - Development and Programming VB.net Webpart in Sharepoint

Pritam Dahake

SoloHiker,

Thanks a lot for sharing your vb.net code for webparts. Have you tried inheriting your web part class from Microsoft.SharePoint.WebPartPages.WebPart

Also, when you deploy your webpart to the bin directory and add a safe entry for it in the web.config file, do you see the webpart in the webpart gallery when you click on "New" in the webpart gallery

Thanks

-Pritam