Tuesday, September 22, 2009

Open popup in button click event

Hello guys

Add below C# code in button click event.

StringBuilder sb = new StringBuilder();
sb.Append("");
System.Web.UI.ScriptManager.RegisterStartupScript(this.upnlStd, this.GetType(), "sb", sb.ToString(), false);

Monday, September 7, 2009

Add thumbnail in skin

Hello Friends

Follow the below step for add thumbnail to skin and container in DNN.

Step 1: Suppose your project name is TestThumbnail.
Step 2: You have create skin in your project at the location TestThumbnail\Portals\_default\Skins\TitleBlue.ascx.
Step3 : Your skin name is TitleBlue.ascx. Now you need to add thumbnail at same location with same name.
means TestThumbnail\Portals\_default\Skins\TitleBlue.jpg.

After follow the step you can see the thumbnail in manage skin after login.

Wednesday, August 12, 2009

Change FCKeditor Default Font

Hello Friends

If u want to change the default font in fck editory than change in below .css file.

File Location: fck\editor\css\fck_editorarea.css

Open up the fck_editorarea.css and look for:
below is the default setting.
body, td
{
font-family: Arial, Verdana, sans-serif;
font-size: 12px;
}

change in this and u will get the default setting according to that

Saturday, August 1, 2009

Get Sql Server table structure and Data

Hello friends


Download Microsoft SQL Server Database Publishing Wizard 1.1 using the below link and install it.
Go through it and u will get the script of Sql Server table and its data.

http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en

Thanks & Regards
Jignesh Patel

Thursday, July 16, 2009

Remove default paragraph in FckEditor

Hello Friends

When we work with Editor than it shows default text like "Here it shows blank space" in source...

Also when we press Enter than it will take Paragraph in place of break..

So find the solution using below step.
Step 1 : open the fckeditor/fckconfig.js file
Step 2 : Change in that

FCKConfig.EnterMode = 'br' ; // p | div | br
FCKConfig.ShiftEnterMode = 'p' ; // p | div | br

Step 3 : Save it and remove the cache,cookie,history and check...

Also this solution is work in Dotnetnuke...


Thanks & Regards
Jignesh Patel

Working with Math Equation Editor

Hello friends

Please download the Editor using below link.

Click here to Download

Register fck editor in your page by using

<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

And use it by


Add downloded editor dll in Bin folder and paste FckEditor in your application.

For more detail click here

Enjoy with math equation editor....

Thanks & Regards
Jignesh Patel

Monday, July 13, 2009

Backup using Query in Sql Server

Hello Guys


Execute the below query for create backup file.


EXEC sp_addumpdevice 'disk', 'MyBackupDevice', 'D:\Shared\MyBackup.bak'
BACKUP DATABASE Test TO MyBackupDevice



Here "D:\Shared\MyBackup.bak" is the path of the back up file.
"Test" is the name of database.

Execute it u will get the back up file at "D:\Shared\MyBackup.bak" location.


Thanks & Regards
Jignesh Patel

Monday, July 6, 2009

HTML Codes - Characters and symbols

Hello Friends

You need a html codes for Characters and symbols.

Please go through to below link.

http://www.ascii.cl/htmlcodes.htm

Thanks & Regards
Jignesh Patel

Thursday, June 18, 2009

Working with DotNetNuke

Hello Friends

Below link is useful to work with Dotnetnuke.

Go through it step by step.

http://www.codeproject.com/KB/MCMS/DotNetNuke.aspx

Thanks & Regards
Jignesh Patel

Create module in Dotnetnuke

Hello guys

Dotnetnuke is useful for CMS application.

Below link is useful to create module in Dotnetnuke application.

http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryId/1410/DotNetNuke-4-5-and-ASP-NET-AJAX.aspx

Thanks & Regards
Jignesh Patel

Tuesday, June 2, 2009

Control the Page Numbering in word document

Hello friends

Here is the sample code using that u can set the page number starting from 5.

Microsoft.Office.Interop.Word._Application oWord oWord = new Microsoft.Office.Interop.Word.Application(); oWord.ActiveWindow.Selection.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.RestartNumberingAtSection = true;

oWord.ActiveWindow.Selection.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.StartingNumber = 5;

Thanks & Regards
Jignesh Patel

Monday, June 1, 2009

Create word document using FileStream

Hello guys

U can create word document using FileStrem in C#.Net.

using System.IO;
using System.Text;

Public void CreateWordDoc()
{
string strFileName;
strFileName = Guid.NewGuid().ToString() + ".doc";
string strFilePath = Server.MapPath("NewFile/") + strFileName;
FileStream f = new FileStream(strFilePath, FileMode.Create);
StreamWriter s = new StreamWriter(f);


HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";

HttpContext.Current.Response.ContentType = "application/msword";


HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);

StringBuilder strHTMLContent = new StringBuilder();

HttpContext.Current.Response.ContentType = "application/msword";


HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
HttpContext.Current.Response.Charset = "";

System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);

tbmMain.RenderControl(hw); //Where dv is div holding img with run at server
HttpContext.Current.Response.Write(tw.ToString());

// create a write stream

// write to the stream
string str=tw.ToString();
s.WriteLine(str);
s.Close();
f.Close();

}
Thanks & Regards
Jignesh Patel

Friday, May 22, 2009

Add blank page in word document using C#.Net

Hello Friends

U can add blank page at particular page number in word document using below code.

object missing = System.Reflection.Missing.Value;
object fileName = @"D:\TestFile.docx";
object readOnly = false;
object isVisible = true;

//Start Word and open a document.
_Application oWord;
_Document oDoc;
oWord = new Application();
oWord.Visible = true;

oDoc = oWord.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref isVisible, ref missing,
ref missing, ref missing, ref missing);

//Goto some specific page and insert a blank page or page break
object gotoPage = WdGoToItem.wdGoToPage;
object gotoNext = WdGoToDirection.wdGoToNext;
object gotoCount = null;
//Page Numer
object gotoName = "4";

oWord.Selection.GoTo(ref gotoPage, ref gotoNext, ref gotoCount, ref gotoName);

//Insert a blank page
oWord.Selection.InsertNewPage();

//Insert a page break
object breakPage = WdBreakType.wdPageBreak;
oWord.Selection.InsertBreak(ref breakPage);

Thanks & Regards
Jignesh Patel

Tuesday, May 19, 2009

Create Web Service in .Net

Hello Friends

Here sample code for how to create web service and consume int in C#.Net.

Step 1 : Add new Web Service(.asmx) file using add New Item
Step 2 : Suppose i have add Operation.asmx file
Step 3 :Add namespace of web service
///


/// Summary description for Operation
///

[WebService(Namespace = "http://localhost:3870/ConnectMySql/Operation.asmx")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
Step 4 : Create Function using [WebMethod]
//[WebMethod]
public int Addition(int a,int b)
{
int c;
c = a + b;
return c;
}
Step 5: Now build the web site and web service is created.

Now for Consume Web Service Step

Step 6: Add web service referance to another site using right click on project and add web referance.
Enter web service url http://localhost:3870/ConnectMySql/Operation.asmx and add namespace name for exa. "localhost".
Step 7 : Now add Namespace in page by
using localhost
Step 8 : Create object of Operation Class
Operation obj = new Operation();
int a = obj.Addition(5,2)
Response.Write(a.ToString());

Thanks & Regards

Jignesh Patel


Friday, May 15, 2009

Create Random number in .Net

You guys can create random number using below code up to 6 digit if u want to more than change in for loop.

public string CreateRandomCode()
{
string allChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
string[] allCharArray = allChar.Split(',');
string randomCode = "";
int temp = -1;

Random rand = new Random();
for (int i = 0; i < 6; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
}
int t = rand.Next(36);
if (temp != -1 && temp == t)
{
return CreateRandomCode(codeCount);
}
temp = t;
randomCode += allCharArray[t];
}
return randomCode;
}

Thanks & Regards
Jignesh Patel

Bind Treeview in .Net

Hello friends

Here the code for bind treeview up to four level.In this example i have bind Subject-->SubSubject-->Chapter-->Topic.

#region BIND TREE VIEW NODE

#region BIND Subject
private void BindMaterial()
{

strQuery = "SELECT Subject,SubjectId FROM V_GetStudentMaterial GROUP BY Subject,SubjectId ";


DataTable dtMaterial;
dtMaterial = ObjB.SelectMaterial(strQuery);
if(dtMaterial.Rows.Count>0)
{
tvMaterail.Nodes.Clear();
for (int iTreeSubject = 0; iTreeSubject < dtMaterial.Rows.Count; iTreeSubject++)
{
TreeNode SubjectNode = new TreeNode();
SubjectNode.Text = FormatStrDecode(dtMaterial.Rows[iTreeSubject]["Subject"].ToString());
SubjectNode.Value = dtMaterial.Rows[iTreeSubject]["SubjectId"].ToString();
SubjectNode.ToolTip = FormatStrDecode(dtMaterial.Rows[iTreeSubject]["Subject"].ToString());
SubjectNode.Expand();
//Bind Subject
tvMaterail.Nodes.Add(SubjectNode);
int intTreeSubjectId = int.Parse(SubjectNode.Value.ToString());
BindSubSubjectNodes(SubjectNode, intTreeSubjectId);
}
trMaterial.Visible = true;
lblMessage.Text = "";
}
else
{
lblMessage.Text = ReadXMLFile_Admin(FormName.Topic, Task.Materialnotfound);
trMaterial.Visible = false;
}

}
#endregion

#region BIND SUB SUBJECT NODE
private void BindSubSubjectNodes(TreeNode ParentSubjectNode, int intTreeSubjectId)
{
try
{
strQuery = "";
strQuery = "SELECT Subject,SubjectId,SubSubject,SubSubjectId FROM V_GetStudentMaterial WHERE SubjectId=" + intTreeSubjectId + " GROUP BY Subject,SubjectId,SubSubject,SubSubjectId";
DataTable dtSubSubject;
dtSubSubject = ObjB.SelectMaterial(strQuery);
if (dtSubSubject.Rows.Count > 0)
{
for (int intiSubSubject = 0; intiSubSubject < dtSubSubject.Rows.Count; intiSubSubject++)
{
TreeNode SubSubjectNode = new TreeNode();
SubSubjectNode.Text = dtSubSubject.Rows[intiSubSubject]["SubSubject"].ToString();
SubSubjectNode.Value = dtSubSubject.Rows[intiSubSubject]["SubSubjectId"].ToString();
SubSubjectNode.ToolTip = FormatStrDecode(dtSubSubject.Rows[intiSubSubject]["SubSubject"].ToString());
//Bind Sub Subject
ParentSubjectNode.ChildNodes.Add(SubSubjectNode);
int intSubSubjectId = int.Parse(SubSubjectNode.Value.ToString());
BindChildChapter(SubSubjectNode, intSubSubjectId);
ParentSubjectNode.Collapse();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion

#region BIND SUB SUBJECT CHAPTER NODE
private void BindChildChapter(TreeNode ParentSubSubjectNode, int intTreeSubSubjectId)
{
try
{
strQuery = "";
strQuery = "SELECT Subject,SubjectId,SubSubject,SubSubjectId,ChapterId,ChapterName FROM V_GetStudentMaterial WHERE SubSubjectId=" + intTreeSubSubjectId + " GROUP BY Subject,SubjectId,SubSubject,SubSubjectId,ChapterId,ChapterName";
DataTable dtChapter;
dtChapter = ObjB.SelectMaterial(strQuery);
if (dtChapter.Rows.Count > 0)
{
for (int intiChapter = 0; intiChapter < dtChapter.Rows.Count; intiChapter++)
{
TreeNode ChapterNode = new TreeNode();
ChapterNode.Text = dtChapter.Rows[intiChapter]["ChapterName"].ToString();
ChapterNode.Value = dtChapter.Rows[intiChapter]["ChapterId"].ToString();
ChapterNode.ToolTip = FormatStrDecode(dtChapter.Rows[intiChapter]["ChapterName"].ToString());
//Bind Chapter
ParentSubSubjectNode.ChildNodes.Add(ChapterNode);
int intChapterId = int.Parse(ChapterNode.Value.ToString());
BindChildChapterTopic(ChapterNode, intChapterId);
ParentSubSubjectNode.Collapse();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion

#region BIND CHAPTER TOPIC NODE
private void BindChildChapterTopic(TreeNode ParentChapterNode, int intTreeChapterId)
{
try
{
strQuery = "";
strQuery = "SELECT Subject,SubjectId,SubSubject,SubSubjectId,ChapterId,ChapterName,TopicId,Topic FROM V_GetStudentMaterial WHERE ChapterId=" + intTreeChapterId + " GROUP BY Subject,SubjectId,SubSubject,SubSubjectId,ChapterId,ChapterName,TopicId,Topic";
DataTable dtTopic;
dtTopic = ObjB.SelectMaterial(strQuery);
if (dtTopic.Rows.Count > 0)
{
for (int intiTopic = 0; intiTopic < dtTopic.Rows.Count; intiTopic++)
{
TreeNode ChapterNode = new TreeNode();
ChapterNode.Text = dtTopic.Rows[intiTopic]["Topic"].ToString();
ChapterNode.Value = dtTopic.Rows[intiTopic]["TopicId"].ToString();
ChapterNode.ToolTip = "Click here to view " + FormatStrDecode(dtTopic.Rows[intiTopic]["Topic"].ToString());
ChapterNode.NavigateUrl = "ContentDetail.aspx?TopicId=" + dtTopic.Rows[intiTopic]["TopicId"].ToString();
//Bind Topic
ParentChapterNode.ChildNodes.Add(ChapterNode);
ParentChapterNode.Collapse();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion


#endregion

Thanks & Regards
Jignesh Patel

Thursday, May 14, 2009

Add an Image in Word Document using .Net

Hello friends

Using the sample code u can add image in word document.

//Insert Image
string strSiteURL ="www.url.com"
object oRngHeader;
Microsoft.Office.Interop.Word.Paragraph oParaHeader;

oRngHeader = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oParaHeader = oDoc.Content.Paragraphs.Add(ref oRngHeader);

wrdSelection = oWord.Selection;
wrdSelection.TypeText(oParaHeader.Range.Text);

string strObjHeaderFile = strSiteURL + "images/Logo.jpg";
Object oAnsHeader = oParaHeader.Range;

//oParaHeader.Format.SpaceAfter = 1;

oParaHeader.Format.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oParaHeader.Application.Selection.InlineShapes.AddPicture(strObjHeaderFile, ref o_missvalue, ref o_missvalue, ref oRngHeader);

Thanks & Regards
Jignesh Patel

Create Word Document in .Net

Hello

You can create word document with page number in footer
using below code.

using System.Reflection;
using Microsoft.Office.Interop.Word;
private void CreateDocument()
{


object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

//Start Word and create a new document.
Microsoft.Office.Interop.Word._Application oWord;

Microsoft.Office.Interop.Word._Document oDoc;


oWord = new Microsoft.Office.Interop.Word.Application();

oWord.Visible = false;

oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

//Add Border
oDoc.ActiveWindow.Selection.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleDot;
oDoc.ActiveWindow.Selection.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleDot;
oDoc.ActiveWindow.Selection.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleDot;
oDoc.ActiveWindow.Selection.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleDot;


oDoc.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4;
oDoc.PageSetup.LayoutMode = WdLayoutMode.wdLayoutModeLineGrid;
oDoc.PageSetup.PageWidth = oWord.InchesToPoints(7F);
oDoc.PageSetup.PageHeight = oWord.InchesToPoints(14F);

//Insert a paragraph at the beginning of the document.
Microsoft.Office.Interop.Word.Paragraph oPara1;
object oRngHed;
oRngHed = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
//Assign text
oPara1.Range.Text = "This is test for create word document";
oPara1.Format.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oPara1.Range.Font.Bold = 10;
oPara1.Range.Font.Size = 18;
//oPara1.Format.SpaceAfter = 2; //24 pt spacing after paragraph.
oPara1.Range.InsertParagraphAfter();




string strFileName;
strFileName = Guid.NewGuid().ToString() + ".doc";
object o_filename = Server.MapPath("NewFile/") + strFileName;
object o_format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatEncodedText;
object o_endings = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
object o_null = Missing.Value;

oDoc.PageSetup.TopMargin = oWord.MillimetersToPoints(14.17F);
oDoc.PageSetup.BottomMargin = oWord.MillimetersToPoints(14.17F);
oDoc.PageSetup.RightMargin = oWord.MillimetersToPoints(14.17F);
oDoc.PageSetup.LeftMargin = oWord.MillimetersToPoints(14.17F);



oWord.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageFooter;

//ENTERING A PARAGRAPH BREAK "ENTER"

oWord.Selection.TypeParagraph();



//INSERTING THE PAGE NUMBERS CENTRALLY ALIGNED IN THE PAGE FOOTER

//string docNumber = "1";

//string revisionNumber = "0";

oWord.Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;

oWord.ActiveWindow.Selection.Font.Name = "Arial";

oWord.ActiveWindow.Selection.Font.Size = 8;

// oWord.ActiveWindow.Selection.TypeText("Document #: " + docNumber + " " + revisionNumber);



//INSERTING TAB CHARACTERS


oWord.ActiveWindow.Selection.TypeText("");

oWord.ActiveWindow.Selection.TypeText("");



oWord.ActiveWindow.Selection.TypeText("Page ");

object CurrentPage = WdFieldType.wdFieldPage;

string str;
str = oWord.Selection.HeaderFooter.PageNumbers.Count.ToString();
oWord.ActiveWindow.Selection.Fields.Add(oWord.Selection.Range, ref CurrentPage, ref oMissing, ref oMissing);

oWord.ActiveWindow.Selection.TypeText(" of ");

object TotalPages = WdFieldType.wdFieldNumPages;

// oWord.ActiveWindow.Selection.Fields.Add(oWord.Selection.Range, ref TotalPages, ref oMissing, ref oMissing);



//SETTING FOCUES BACK TO DOCUMENT

oWord.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;
oWord.Selection.TypeParagraph();

oWord.Selection.Font.Bold = 1;

oWord.Selection.Font.Color = WdColor.wdColorAqua;

oWord.Selection.Font.Italic = 1;

oWord.Selection.Font.Underline = WdUnderline.wdUnderlineDashHeavy;
oWord.Selection.ClearFormatting();



oDoc.SaveAs(ref o_filename, ref o_format, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_endings, ref o_null);

//Assign null value to created object
oDoc = null;
oWord.Quit(ref o_null, ref o_null, ref o_null);
//For Open file
Response.Redirect("NewFile/" + strFileName);
}

if u have any query than send it.

Thanks & Regards
Jignesh Patel