Wednesday 20 april 2011 3 20 /04 /Apr /2011 08:50

We can log different errors or information while writing code for any .NET application, here is a generic class written for logging:

Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Security.Permissions;

namespace Common
{
/*This Class is used for logging messages to either a custom EventViewer or in a plain text file located on web server.
* Owner : Deepak Solanki
* Year : 2011 */

public class Logging
{
#region "Variables"

private string sLogFormat;
private string sErrorTime;

#endregion


#region "Local methods" 

/* Write to Txt Log File*/ 
public void WriteToLogFile(string sErrMsg)
{
try
{
//sLogFormat used to create log format :
// dd/mm/yyyy hh:mm:ss AM/PM ==> Log Message
sLogFormat = DateTime.Now.ToShortDateString().ToString() + " " + DateTime.Now.ToLongTimeString().ToString() + " ==> ";

//this variable used to create log filename format "
//for example filename : ErrorLogYYYYMMDD
string sYear = DateTime.Now.Year.ToString();
string sMonth = DateTime.Now.Month.ToString();
string sDay = DateTime.Now.Day.ToString();
sErrorTime = sYear + sMonth + sDay;

//writing to log file
string sPathName = "C:\\Logs\\ErrorLog" + sErrorTime;
StreamWriter sw = new StreamWriter(sPathName + ".txt", true);
sw.WriteLine(sLogFormat + sErrMsg);
sw.Flush();
sw.Close();
}
catch (Exception ex)
{
WriteToEventLog("MySite", "Logging.WriteToLogFile", "Error: " + ex.ToString(), EventLogEntryType.Error);
}
}

/* Write to Event Log*/
public void WriteToEventLog(string sLog, string sSource, string message, EventLogEntryType level)
{
//RegistryPermission regPermission = new RegistryPermission(PermissionState.Unrestricted);
//regPermission.Assert();

if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);

EventLog.WriteEntry(sSource, message, level);
}

#endregion
}
}


Happy Coding!!! 

By Deepak Singh Solanki - Posted in: .NET
Enter comment - View the 0 comments
Wednesday 20 april 2011 3 20 /04 /Apr /2011 08:43

Requirement is to show news on web page, data saved in custom list. A webpart to get data from list and show on page:

1. Open Visual Studio and create a class file or webpart (if sharepoint extension is there with VS.
2. Code of ShowNews.cs file below:


using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Drawing;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace MyWebParts
{
[Guid("6e1a7cf2-bf98-4926-81c9-0c0184ba6a60")]
public class ShowNews : System.Web.UI.WebControls.WebParts.WebPart
{

//Controls
private Label lblTitle;
private Label lblNews; 

// A table that is used to layout the controls
private Table tbMain;
private TableRow tRow;
private TableCell tCell;

#region "Web Part Properties"

private const string defaultSiteCollection = "NewTeamSite";
private string _siteName = defaultSiteCollection;
[Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
WebDisplayName("Site Name"),
WebDescription("Site from where to fetch News")]

public string SiteName
{
get { return this._siteName; }
set { this._siteName = value; }
}

private const string defaultList = "News";
private string _listName = defaultList;
[Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
WebDisplayName("List Name"),
WebDescription("List from where to fetch News")]

public string ListName
{
get { return this._listName; }
set { this._listName = value; }
}
#endregion

public ShowNews()
{
}

protected override void CreateChildControls()
{
base.CreateChildControls();

// TODO: add custom rendering code here.
tbMain = new Table();
tbMain.BorderStyle = BorderStyle.Double;
tbMain.BorderColor = Color.Silver;
tbMain.BackColor = Color.WhiteSmoke;


lblTitle = new Label();
lblTitle.Text = "News";
lblTitle.Font.Bold = true;

tRow = new TableRow();
tCell = new TableCell(); 
tCell.VerticalAlign = VerticalAlign.Top;
tCell.HorizontalAlign = HorizontalAlign.Center;
tCell.Controls.Add(lblTitle);
tRow.Controls.Add(tCell);
tbMain.Controls.Add(tRow);


lblNews = new Label();
lblNews.Text = "Blank"; 

tRow = new TableRow();
tCell = new TableCell();
tCell.VerticalAlign = VerticalAlign.Top;
tCell.HorizontalAlign = HorizontalAlign.Left;
tCell.Controls.Add(lblNews);
tRow.Controls.Add(tCell);
tbMain.Controls.Add(tRow);

this.Controls.Add(tbMain);

CreateNewsHtml();
}

private void CreateNewsHtml()
{
SPList newsList;
SPListItemCollection listitemcoll;

try
{
using (SPSite site = new SPSite(this.Context.Request.Url.ToString()))

using (SPWeb web = site.AllWebs[this._siteName])
{
newsList =web.Lists[this._listName];
listitemcoll = newsList.Items;
if (newsList.ItemCount > 0)
foreach(SPListItem item in listitemcoll)
{
lblTitle.Text = item["Title"].ToString();
lblNews.Text = item["News"].ToString();
}

}
}
}
catch (Exception ex)
{

}
}
}
}


3. Create ShowNews.webpart file (get created itself with Sharepoint extension)

<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData> 
<type name="MyWebparts.ShowNews, ShowNews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXXXX" />
<importErrorMessage>Cannot import ShowNews Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">ShowNews Web Part</property>
<property name="Description" type="string">Show News from List on Page</property>
<property name="AllowZoneChange" type="bool">True</property>
<property name="AllowHide" type="bool">True</property>
</properties>
</data>
</webPart>
</webParts>


4. Now, your webpart is ready, deploy it either [1] manually; GAC the DLL, upload webpart file to webpart gallery and made safecontrol entry for webpart in web.config file. or [2] create a deployment package to deploy the webpart.

Happy Coding!!! 

By Deepak Singh Solanki - Posted in: Sharepoint
Enter comment - View the 0 comments
Tuesday 21 december 2010 2 21 /12 /Dec /2010 06:51

Sometimes you want to share a folder or to implement\change some security settings or access rights but you wonder, in folder properties, where the Security tab is? It could happen to you even if you have administrator rights. Here are few simple steps to solve the problem.

So to see and unhide the Security tab, just use the following steps:
1. Launch Windows Explorer or My Computer.
2. Click on the Tools at the menu bar, and then click on Folder Options.
3. Click on View tab.
4. In the Advanced Settings section at the bottom of the list, uncheck and unselect (clear the tick) on the “Use simple file sharing (Recommended)” check box.
5. Click OK.

Security tab is available only to Administrator or users with administrative rights. So make sure you login as one. And security can only be set in an NTFS partition. If you’re still having problem to reveal or display the Security tab on files or folder properties, check out the following registry hack and set the value to 0 or simply delete the key:
Hive: HKEY_CURRENT_USER
Key: Software\Microsoft\windows\CurrentVersion\Policies\Explorer
Name: Nosecuritytab
Type: REG_DWORD
Value: 1

I hope it works for you..

By Deepak Singh Solanki - Posted in: Technology
Enter comment - View the 0 comments
Wednesday 15 december 2010 3 15 /12 /Dec /2010 08:04

This is one of the basic requirements of a site; you may want to play a media file or a play list (group of media files).  Here are few simple steps to create a web page with media player on it.

  1. Open Visual Studio 2005\2008
  2. File à New à Website, Give this site a name, like MySite
  3. Create a new folder under your site, Right Click on site à New Folder, name it Videos.
  4. Copy all the media files you want to play on site.
  5. Create a playlist, Right click on Videos folder à Add New Item à Text File à Name it Playlist.m3u
  6. Open the Playlist.m3u file and provide list of files with relative location in this, each file in new line. I.e. - 

/MySite/Videos/Evian.wmv

/MySite/Videos/Too_Good.mpeg

  1. Now, open the Default.aspx page, and add following code in <div> or <table> as per you site layout:

<object id="MediaPlayer1" width="360" height="400" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"

codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"

standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject"

style="text-align: center;">

<param name="FileName" value="Videos/Playlist.m3u" />                   

<param name="loop" value="True" />

<param name="ShowStatusBar" value="True" />

<param name="DefaultFrame" value="mainFrame" />

<param name="autostart" value="true" />

</object>

  1. Save the file and Run this site. It will play the playlist provided.

Note- if you want to play just a single file in Media Player, just replace the line

<param name="FileName" value="Videos/Playlist.m3u" />                   

With line

<param name="src" value="Videos/Too_Good.mpeg" />

 

Happy Coding!!!

By Deepak Singh Solanki - Posted in: .NET
Enter comment - View the 0 comments
Tuesday 29 december 2009 2 29 /12 /Dec /2009 14:15

In MOSS site there is built-in functionality for sending\receiving mails for alerts, workflows, events etc. Here are simple steps to configure e-mail on Sharepoint server through Sharepoint Central Administrator.

 

 Configure incoming e-mail

 
Configure incoming e-mail settings  You can configure incoming e-mail settings so that SharePoint sites accept and archive incoming e-mail. You can also configure incoming e-mail settings so that SharePoint sites can archive e-mail discussions as they happen, save e-mailed documents, and show e-mailed meetings on site calendars. In addition, you can configure the SharePoint Directory Management Service to provide support for e-mail distribution list creation and management.

To enable incoming e-mail by using automatic mode, you must install the Internet Information Services (IIS) Simple Mail Transfer Protocol (SMTP) server.

By specifying a drop folder, you can enable incoming e-mail by not using an SMTP server.

  1. On the top navigation bar, click Operations.
  2. On the Operations page, in the Topology and Services section, click Incoming e-mail settings.
  3. If you want to enable sites on this server to receive e-mail, on the Incoming E-mail Settings page, in the Enable Incoming E-Mail section, select Yes.
  4. Select either the Automatic or the Advanced settings mode.

If you select Advanced, you can specify a drop folder instead of using an SMTP server.

  1. If you want to connect to the SharePoint Directory Management Service, in the Directory Management Service section, select Yes.

You can connect to the SharePoint Directory Management Service for SharePoint sites to manage e-mail addresses in SharePoint lists.

  1. In the Directory Management Service URL box, type the URL of the SharePoint Directory Management Service.
  2. In the E-mail server display address box, type the e-mail server name (for example, mail.sharepoint.fabrikam.com).
  3. Answer the following two questions by selecting Yes or No:
    • Does the Directory Management Service manage distribution lists?
    • Should distribution lists accept mail only from authenticated senders?
  4. In the Incoming E-Mail Server Display Address section, type a display name for the e-mail server (for example, mail.fabrikam.com) in the E-mail server display address box.

Tip  You can specify the e-mail server address that is displayed when users create an incoming e-mail address for a list or group. Use this setting in conjunction with the SharePoint Directory Management Service to provide an e-mail server address that is more user-friendly.

  1. In the Safe E-Mail Servers section, select one of the following options:
    • Accept mail from all e-mail servers
    • Accept mail from these safe e-mail servers. If you select this option, type the IP addresses (one per line) of the e-mail servers that you want to specify as safe in the corresponding box.
  2. In the E-mail Drop Folder section, in the E-mail drop folder box, type the name of the folder in which Microsoft Windows SharePoint Services polls for incoming e-mail from the Windows SMTP Service.

This option is available only if you selected advanced mode.

  1. Click OK.

 

  • Configure outgoing e-mail settings  You can configure outgoing e-mail settings so that your Simple Mail Transfer Protocol (SMTP) server sends e-mail alerts to site users and notifications to site administrators. You can configure both the "From" e-mail address and the "Reply" e-mail address that appear in outgoing alerts.

 

Configure outgoing e-mail

Configure default outgoing e-mail settings

Configuring the default outgoing e-mail settings configures the default outgoing e-mail settings for all Web applications.

  1. On the top navigation bar, click Operations.
  2. On the Operations page, click Outgoing e-mail settings in the Topology and Services section.
  3. On the Outgoing E-Mail Settings page, in the Mail Settings section, type the Simple Mail Transfer Protocol (SMTP) server name for outbound e-mail (for example, mail.example.com) in the Outbound SMTP server box.
  4. In the From address text box, type the from address as you want it to appear to e-mail recipients.
  5. In the Reply-to address box, type the e-mail address to which you want e-mail recipients to reply.
  6. In the Character set menu, select the character set appropriate for your language.
  7. Click OK.

Configure outgoing e-mail settings for a Web application

You can override a Web application's default settings for outgoing e-mail.

  1. On the top navigation bar, click Application Management.
  2. On the Application Management page, click Web application outgoing e-mail settings in the SharePoint Web Application Management section.
  3. On the Web Application E-Mail Settings page, select a Web application by using the Web Application menu in the Web Application section.
  4. In the Mail Settings section, type the SMTP server name for outbound e-mail (for example, type mail.fabrikam.com) in the Outbound SMTP server box.
  5. In the From address box, type the e-mail address as you want it to appear to e-mail recipients.
  6. In the Reply-to address box, type the e-mail address to which you want e-mail recipients to reply.
  7. On the Character set menu, click the character set that's appropriate for your language.
  8. Click OK.

 

By Deepak Singh Solanki - Posted in: Sharepoint
Enter comment - View the 0 comments

Overview

Create a blog

Calendar

January 2012
M T W T F S S
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
<< < > >>
Create your blog for free on over-blog.com - Contact - Terms of Service - Earn Royalties - Report abuse