If you ever wished that the Datalist control of Visual Studio 2005 could have paging enabled with it ,then it has come true but in the form of a new control named ListView.
ListView Control of Visual Studio 2008 is Quiet interesting ,Lets see how can we use this control in our project .
Now fire up Visual Studio 2008 and open a new website project .
Suppose that you have a SQL database table with three columns as First name ,Last name ,email .
Drag and drop an Sqldatasource control from the toolbox and configure it to your SQL database table .
Now drag and drop a ListView Control from the Toolbox and declare its DatasourceID to be the above datasource .
A listview control has a list of 11 Templates for configuring the Look and Feel of the listview control .But the most important part of the control is that it requires a Placeholder whose ID needs to be exactly the same as "itemplaceholder" like the code below.........
(asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1")
(LayoutTemplate)
(asp:PlaceHolder ID="itemplaceholder" runat="server")(/asp:PlaceHolder)
(/LayoutTemplate)
(use the <> brackets instead of ( ) in the code )
Now add an item template to show your data like the code below ..........
(ItemTemplate )
(asp:Label ID="label1" runat="server" Text='(%#Eval("Firstname") %)'/)(br /)
(asp:Label ID="label2" runat="server" Text='(%#Eval("Lastname") %)'/)(br /)
(asp:Label ID="label3" runat="server" Text='(%#Eval("email") %)'/)(br /)
(/ItemTemplate)
You can the use other templates to make it look better.......
Now about adding the paging element to the listview control .
Drag and drop the paging control from the toolbox and set its PageControlID to the above Listview control as below ........
(asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1"
PageSize="5")
(Fields)
(asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" /)
(/Fields)
(/asp:DataPager)
Using this control you can set the paging style and also the number of data to be shown on the page .
The Listview control has some more intresting templates like the GroupTemplate which can be used to group data elements together but we may talk about that later in some other Blogpost.
For now you play with this new control of visual studio 2008.
Thursday, May 29, 2008
Uploading Images using Fckeditor
In my previous Blog ,I did write about integrating Fckeditor in Visual studio Projects .
Today ,I will guide you about enabling the Image,Flash file upload in fckeditor.
Due to security reasons this feature is disabled by default .
Once you get the Editor working follow these steps to get upload working .....
1.Create a Folder named "userfiles" in the root directory and add two subfolders to it named image and flash .
2.Go to the web.config file ,In the appSettings write the following code .....
(appSettings)
( add key="FCKeditor:UserFilesPath" value="~/userfiles/"/)
(/appSettings)
3. Go to fckeditor/fckconfig.js and search for
var _FileBrowserLanguage and var _QuickUploadExtension
change the file type to 'aspx' like the below code
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
4. Now move to fckeditor/editor/filemanager/connectors/aspx/config.ascx
find the private bool Check_Authenticate () function
Here you need to tweak the code according to your needs .
If you want only authenticated users to access your browserfiles then add this code
return ( Session[ "IsAuthorized" ] != null && (bool)Session[ "IsAuthorized" ] == true );
//else you can make use of your own custom made function .
else an easy but a bad option is
return true;//not suggested
5. In the same file you need to define the path of your userfile folder .
// URL path to user files.
UserFilesPath = "/userfiles/";
//Absolute path to userfiles
UserFilesAbsolutePath = "C:\\Users\\Documents\\Visual Studio 2008\\WebSites\\ Website\\userfiles\\";
6. The Final Step ,pray to god that it works at last
It took me a week to figure out the way to integrate it and make it work finally ,I hope this Blog will make it a lot more simpler for you now .
I have used version 2.6 of Fckeditor , Visual studio 2008 and .net fx 3.5 for my project.
I hope it works the same with visual studio 2005 and .net fx 2.0.
If you still face any problem with it ,do mail me your problem and I will try to Fix it .
Today ,I will guide you about enabling the Image,Flash file upload in fckeditor.
Due to security reasons this feature is disabled by default .
Once you get the Editor working follow these steps to get upload working .....
1.Create a Folder named "userfiles" in the root directory and add two subfolders to it named image and flash .
2.Go to the web.config file ,In the appSettings write the following code .....
(appSettings)
( add key="FCKeditor:UserFilesPath" value="~/userfiles/"/)
(/appSettings)
3. Go to fckeditor/fckconfig.js and search for
var _FileBrowserLanguage and var _QuickUploadExtension
change the file type to 'aspx' like the below code
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
4. Now move to fckeditor/editor/filemanager/connectors/aspx/config.ascx
find the private bool Check_Authenticate () function
Here you need to tweak the code according to your needs .
If you want only authenticated users to access your browserfiles then add this code
return ( Session[ "IsAuthorized" ] != null && (bool)Session[ "IsAuthorized" ] == true );
//else you can make use of your own custom made function .
else an easy but a bad option is
return true;//not suggested
5. In the same file you need to define the path of your userfile folder .
// URL path to user files.
UserFilesPath = "/userfiles/";
//Absolute path to userfiles
UserFilesAbsolutePath = "C:\\Users\\Documents\\Visual Studio 2008\\WebSites\\ Website\\userfiles\\";
6. The Final Step ,pray to god that it works at last
It took me a week to figure out the way to integrate it and make it work finally ,I hope this Blog will make it a lot more simpler for you now .
I have used version 2.6 of Fckeditor , Visual studio 2008 and .net fx 3.5 for my project.
I hope it works the same with visual studio 2005 and .net fx 2.0.
If you still face any problem with it ,do mail me your problem and I will try to Fix it .
Tuesday, May 27, 2008
Uploading File using C#

You may have seen many complex programs regarding uploading a file ,but in this post ,I will show you a very simple program for uploading a file .
This program is written using C# and Visual Studio 2008.
So Lets get started...................................................................
Fire up visual studio and open a new ASP.NET website
In this webpage add a FileUpload control from toolbox and a button.
Your webpage should look like the above image....................................
At the uploadbutton_click event Write the following code
protected void uploadbutton_Click(object sender, EventArgs e)
{
string strFileName = FileUpload1.PostedFile.FileName;\\Gets the wholepath of the file
string c = System.IO.Path.GetFileName(strFileName);
\\Gets the filename from the whole pathname
FileUpload1.PostedFile.SaveAs("C:\\images\\" + c);
\\ Saves the file in the desired directory (Instead of "C:\\images \\" ,Give the path where
you want to save the file.
Response.write("File uploaded successfully");
}
The above three line code is enough to upload a file,isnt it easy.
But if you want some extra information about the file being uploaded then you can use the following code
string filesize=FileUpload1.PostedFile.ContentLength.ToString();
\\ Gets the size of the file
string Content=FileUpload1.PostedFile.ContentType;
\\Gets the content type of file whether the file is an image or text
Using this additional code you can make your website more safe by restricting the kind of content being uploaded to the web server.
And the most Important thing
try testing this code on a seperate hard drive first before using it directly on your web server or on your Computers primary Hard drive ..................
Sunday, May 25, 2008
Integrating Fck-Editor

There are Quiet a few HTML -Editors or WYSIWYG(What you see is What you get) Editors avialable on net but I found this a lot more suitable for my website as it is totally free and a full featured Editor. Well this blog is About Integrating Fck-Editor with Visual-Studio to be used on .Net framework.
For Integrating Fck-editor you need to download Fck-editor.net and Fck-Editor script from here.
Then Fire up visual studio 2005/2008 version .
Open the website project you want to integrate this into
Right Click on the project name in Solution Explorer
Add Existing Item
Browse to Folder of Fckeditor.net
Bin->Release->version number(2.0)->FredCK.FCKeditorV2.dll
After adding the binary
Add the fckeditor folder to the project website folder .
And now when you Debug Your program it will show an Error .
The Most Important thing to be done is to change the 'Basepath 'of Fckeditor to '~/fckeditor/'in the properties window .
Adding the ~ sign specifies its location in the root folder.
After this your Editor will work perfectly.
Labels:
.net,
html-editor,
Integrating Fck-editor,
visual studio
Subscribe to:
Posts (Atom)