Saturday, December 19, 2009
How to add validations to a FileUpload control in c#
The following article gives an excellent demostration.
http://msdn.microsoft.com/en-us/library/aa478971.aspx
Thursday, December 17, 2009
How to Poppulate a dropdown in a gridview in Row Editing
{
if (e.Row.RowType == DataControlRowType.DataRow &&
(e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
{
// Here you will get the Control you need like:
DropDownList dl = (DropDownList)e.Row.FindControl("ddlPBXTypeNS");
}
}
That if will only be valid for a DataRow (the actually row with data) and if it's in Edit mode... because you only Edit one row at a time the e.Row.FindControl("ddlPBXTypeNS") will only find the control that you want.
For More Info....
Visit
http://stackoverflow.com/questions/833490/asp-net-3-5-gridview-row-editing-dynamic-binding-to-a-dropdownlist
Tuesday, December 15, 2009
asp.net ajax client-side framework failed to load.
But it was working fine yesterday.Even code reverting didn't work for me.Then I found .Net 3.5 SP1 in my Control Panel - Add/Remove Programs. I clicked Change... and was relieved to see a "Repair" option.
With bated breath I waited for Windows to complete the repair. After a few minutes, I saw that the repair was complete. Now for the test. I ran my web application and all of the Ajax errors disappeared.
Perhaps this was coincidental; who knows. I suppose I could go through my logs, but I'm back in business and that is good enough for me. Of course, this doesn't explain how Ajax got broken in the first place.
Sunday, December 13, 2009
Ajax Grid View With Insert Edit Delete
http://ramanisandeep.wordpress.com/2008/11/16/gridview-insert-update-delete/
Thursday, December 3, 2009
Disadvantages in content editor web part in sharepoint
Unfortunately there are several serious issues with Content Editor :
- Content Editor Web Part content isn’t versioned. You can create as many versions the web part page as you like, the actual content – which is contained within the Content Editor Web Part – isn’t versioned. This is a wider problem with web parts in general, but especially of note when attempting to provide web content management.
- Content Editor Web Part content can’t be searched. Yes, this is as bad as it seems. Add your content to the Content Editor Web Part and it can’t be seen by the WSS Search.
There is another issue with the Content Editor Web Part; whenever you re-open the web part to update content it turns all server-relative URLs into absolute URLs. Therefore if you have your content accessible from different addresses (when you have an extranet and an intranet for example) any linked content will be broken for one of them as soon as anyone updates the content. The only way around this is to edit the HTML directly. Hardly suitable for non-technical users.
Solution
In a nutshell: create a Content Type to contain the web content within the page itself and make use of the superior Telerik RadEditor Lite content editor.
Thursday, November 26, 2009
Advantages of storing images in database over file system
- If the images binary data is stored in a database table, we have all the data required to make the image any size we want, and it will always look like the orginal image
- If the images binary data is stored in a database table, when we back the database up, we have also backed up all the users images
- We can store meta data corresponding to the images that we store
Tuesday, November 17, 2009
How to Add & Retrieve Images from a SQL database using LINQ in c#
Today I received an email from a friend, asking how to save a binary file in to the database using LINQ to SQL. This was the second time a person had asked me the same question, So I thought of having a blog entry about it.
Assume that we need to upload a file and save its name, and the file in the database table. so lets see how we do it.
This is my Table
CREATE TABLE [dbo].[Files2](
[ID] [int] IDENTITY(1,1) NOT NULL,
[FileName] [varchar](50) NOT NULL,
[FileSource] [image] NOT NULL,
)
GO
And The Following Stored Procedure is used to Insert the Value:
CREATE PROCEDURE [dbo].[ADDFILE]
(
@FILENAME VARCHAR(50),
@FILESOURCE image
)
AS
SET NOCOUNT ON
INSERT INTO Files([FileName],[FileSource])
VALUES(@FILENAME,@FILESOURCE)
1.Storing Images
The following code is used to upload and save the file using web form with a text box for file name, and a file upload control to upload the file. on the click event of a button this code is called.
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUploader.HasFile && FileUploader.PostedFile.ContentLength > 0)
{
string filename = txtFileName.Text;
//Read the file in to a byte Array.
byte[] filebyte = FileUploader.FileBytes;
System.Data.Linq.Binary fileBinary = new System.Data.Linq.Binary(filebyte);
MyDataDataContext MyData = new MyDataDataContext();
MyData.ADDFILE(filename, fileBinary);
lblStatus.Text = "File Uploaded Successfully!";
}
}
The Main thing to remember here is that we need to pass the FileUploader.FileBytes to the constructor of System.Data.Linq.Binary.
2.Rerieving Images
context.Response.ContentType = "image/jpeg";
MyDataDataContext ctx = new MyDataDataContext();
//This part os for to getting the image file from data base
Img img = ctx.Imgs.SingleOrDefault(c => c.id == 2);
byte[] ret = img.image.ToArray();
context.Response.BinaryWrite(ret);