.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Public Sub

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :ASP.Net


i'm quite new to asp.net using vb.

at the moment i've got created a sub to write some actions to a xml log file.

everything works fine, the only thing is that i need the source code on multiple pages, is there a way to include this code from a sepperate file, so when i've got some changes to make to the sub i only have to change it once?


    Private sub WriteXML(ByVal XMLAction As String, ByVal XMLType As String)
        Dim f As File
        Dim FileName As String = Server.MapPath("log\log.xml")
        Dim lines As List(Of String) = New List(Of String)(File.ReadAllLines(FileName))

        'Remove Last Line
        lines.RemoveAt(lines.Count - 1)
        File.WriteAllLines(FileName, lines.ToArray())

        Dim fstream As FileStream
        If f.Exists(FileName) Then
            fstream = New FileStream(FileName, FileMode.Append, FileAccess.Write)
            fstream = New FileStream(FileName, FileMode.Create, FileAccess.ReadWrite)
        End If
        Dim sWriter As New StreamWriter(fstream)

        'Write Lines To XML File
    		sWriter.Write("<Type>" 			+ XMLType 				+ "</Type>" 		+ Environment.NewLine)

View Complete Post

More Related Resource Links

Public Shared function doubt????

I am using VB.net/ASP.NET and SQL Server 2000 for a web application.

For populating the dropdowns, I wrote a Public Shared function LoadDDL(), in which I pass the dataset and dropdown name to set.

I have my doubts that this function will produce unexpected results for concurrent users. And will mix the results among sessions because it is a Shared function.

I am confused here. Is it the right way to go?

Please advice. Thanks in advance.


NUnit and public static readonly


I have an app that I am testing with NUNit.  The project im testing has several helper classes that are created as public static readonly.  When I run the NUnit tests, they all fail with the same error

SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.
SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.

I kept getting this error despite stripping out all

public object on asp,net page


in asp.net can i make public objects on my page, for example

public Customer cust1 = new customer();

and use this object on my entire code???

what are the drawbacks of creating public objects??

a single object will be created for all users??? or each user will have a different object????

How do I publish public facing SharePoint site(on internet)?

I developed public facing SharePoint 2010 portal publishing website using Window Server 2008 R2 and SharePoint 2010 Server and SPD 2010 on my computer. I have custom master page, page layout, css…. I want to publish it(on the internet).  I want to know cheap host and domain name service provider Company and steps to do it. I’ appreciate any advice in advance.

Public WCF services for testing clients

I try to find some (public) WCF services out there, but do not succeed. I want to talk to some for testing my work with clients. Any list ?

Hide/remove ribbon on public website

The new ribbon in SP2010 looks nice from a editors point of view. All webparts seems controlled by the contextual ribbon.Using webparts on a public website, like a discussion board, can the webparts be operated without the ribbon? Eg. creating and editing forum posts and other basic operations.The public website is fully skinned and therefore only the editor should see the ribbon for page and webediting. How is this done in SP2010?

Public Variable Creation Question

Hello, I was wondering if there is a way to declare a variable that can be used throughout a page, rather than just in a sub, er private class.  I'm in a situation where I can use session("variable") to set a session variable, but in order to access that I have to trigger a postback. 

CA1063 : Microsoft.Design : Ensure that 'PageContentGrid.Dispose()' is declared as public and seal

OK... I'm getting my DB context like so: private ssCMSDataContext _dataContext; protected ssCMSDataContext DbContext { get { if (_dataContext == null) { _dataContext = new ssCMSDataContext(); } return _dataContext; } } public override void Dispose() { if (_dataContext != null) { _dataContext.Dispose(); } base.Dispose(); } When I run the code analysis I get the following warnings:  "CA1063 : Microsoft.Design : Ensure that 'PageContentGrid.Dispose()' is declared as public and sealed." "CA1063 : Microsoft.Design : Modify 'PageContentGrid.Dispose()' so that it calls Dispose(true), then calls GC.SuppressFinalize on the current object instance ('this' or 'Me' in Visual Basic), and then returns.  I don't understand what it wants me to do?  Little help....  

Dynamic Binding of a Public Property in a User Control

Hi, I am not sure how to pass a variable from an .aspx page to an .ascx page.  I have a Control that puts rotating banners on a page.  The control has several public properties.  However, only one of those properties changes on the page level.  All the other properties are the same for every page site-wide.  So, instead of setting all the properties on every page in my sites (many sites), I want to set it up so I only have to setup the sitewide properties once and only the page level properties on each page.   I want to create a control with a property of AdKeyword="somename" and pass it to another control that will grab that page-level property and add it to all the other site-wide properties.  I guess what I need could be called a Dynamic Control Property.   My .aspx page has:<%@ Register TagPrefix="uc1" TagName="Banner1" Src="banner1.ascx" %> <asp:Content ID="Leaderboard" runat="server" ContentPlaceHolderID="Leaderboard"> <uc1:Banner1 AdKeyword="L2Chamber" runat="server" OverrideHeight="90" /> </asp:Content> My banner1.ascx page has:<%@ Control Language="VB" ClassName="UserControl297" %> <%@ register tagprefix="uc1&

Get Public String in HTML doesn´t work in this case?

Hi, I am trying to retreive a public String in code behind in the HTML code like below but the compiler says that there is Illegal characters in path. I wonder if it is possible to pass a public String here in this case like this ?  <%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true" CodeFile="Hello.aspx.cs" Inherits="Hello" %> <%@ PreviousPageType VirtualPath="<%# previousURL%>" %> (code behind): public String previousURL = "someURL";  

Cannot implement an interface member because it is not public

I have the following code.  When I attempt to build, I get the error message "Cannot implement an interface member because it is not public" on the these three: GetQueryStringValue, SetInSession, and GetFromSession.  If I add public in front of these three, I get the error "the modifier public is not valid for this item".   Any ideas on what I"m doing wrong? Thanks.     public interface IWebContext    {        void ClearSession();        bool ContainsInSession(string key);        void RemoveFromSession(string key);        void GetQueryStringValue(string key);        void SetInSession(string key, object value);        object GetFromSession(string key);    }     public class WebContext : IWebContext    {        public void ClearSession()        {            HttpContext.Current.Session.Clear();        }        public bool ContainsInSession(s

Access Public Function in MasterPage

Hi,I need help in accessing the function in my masterpage.I have a.master and b.aspx with the content page.Now in the page load of my content page, I want to execute the an sql query which is in a function in my master page.How can I access the function in my master page??code in my master page:public function info () as string'SQL Queryend function

Calling a public method on aspx page from a usercontrol

Hello, I have a problem with calling a method on a aspx page from a usercontrol. The case is:I have 1 main page with 5 usercontrols, when something goes wrong in the code I want to display the error message in a Modalpopup Extender.I can create for each usercontrol a different modalpopup extender but isn't much easier when I make 1 popup in the aspx page.But the problem is: How should I call a method in the aspx page that open the popup? I have search several hours on the internet but can't find anything useful. Thanks,  

Cannot access public methods on MasterPage

Hi All, maybe someone can help me with this one. I have a a public method in my code behind on the site.master pagenamespace PROJECT { public partial class Site : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { } public void applyUserRole(string userID) { } } } I  wish to call applyUserRole() from Default.aspx On Default.aspx I have .. <%@ Page Language="C#" MasterPageFile="Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Project- Home" %> <%@ MasterType virtualPath="~/Site.master" %> But when I go to Default.aspx.cs and type Master. the method is not appearing. I've seen other post where people are having this issue but I can't find an answer. If anyone has any good pointer and you please let me know, thanks 

Configure Incoming Email in SharePoint 2010 with a remote (public) SMTP Server

I have a standalone SharePoint 2010 Installation on my local network. Have configured the SMTP Services and a SMTP domain called "internalcompany.com". Created a hosts file entry also for that - now outlook is able to send emails to this domain; it reaches the drop folder and from there SharePoint picks it up and pushes to the document libraries. So far so good. But obviously this is not what I want to do: my www.company.com is my public domain and mail server is mail.company.com - how do I get the local SMTP point to this address - so that if someone sends an email to shareddocs@company.com (just like any other normal id), it comes to my local server and then SharePoint. How do I do this? Remember, my server is standalone and my network is not domain based and does not have exchange.Karthick

Accessing a public property of a nested user control in a master page from a pages' user control

Hi  I've got a web site that has a master page and that master page (mpMaster that has a user control (ucControl1) which has a sub user control (ucControl2), this user control has a property which accepts a value. Now, I have a page that uses the master page and on this page I have another user control (ucPageControl), I need to  find a way of setting the value in ucControl2 from ucPageControl. Is this possible at all? Many thanks Ed

Sharepoint 2010 & Exchange Public folders?

HI All, We are planning to move our Public folders to SharePoint 2010. But Before I would do that. I would like to know: 1. Can we receive emails with attachments in Sharepoint 2010? If yes, how the attachments are stored? Inside the email or separate? 2. How the mail enabled library and lists are different from Mail enabled public folders and Distribution list? 3. What is the format of the mail, .msg or .eml when saved in SharePoint? 4. How do we view content of the sharePoint public folder site inside outlook client? 5. What are features of Public Folders that I can't accomplish using SharePoint 2010?     Your help would be highly appreciated...      
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend