.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

Creating a Custom Exception

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :Windows Application

Hi, Experts

I need to do a custom exception through code. This custom exception will be used so that the user won't be able to upload images of more than 5MB on the server at one time. I am using a fileUpload control to select the path and a button UPLOAD to upload the file on the server. I am using the following code to upload:

if (FileUploader.HasFile)
                string fileExtension = System.IO.Path.GetExtension(FileUploader.FileName).ToLower();
                if (fileExtension.EndsWith(".jpg") || fileExtension.EndsWith(".jpeg") || fileExtension.EndsWith(".bmp") || fileExtension.EndsWith(".png") || fileExtension.EndsWith(".gif"))
                    lblStatus.Visible = true;
                    string fileName = FileUploader.FileName;
                    Session["Image"] = "~/Images/" + fileName;
                    FileUploader.SaveAs(Server.MapPath("~/Images/") + fileName);
                    lblStatus.Text = "Upload Succeded";
                    newProductImg.ImageUrl = "~/Images/" + FileUploader.FileName;
                    ProgressBarUpload.Visible = true;
                    ProgressBarUpload.Value = 100;
                    Response.Write("<script>alert('You can only Upload Image Files')</scr

View Complete Post

More Related Resource Links

Enterprise Library: Take Exception To Critical Errors With Custom Application Blocks


Enterprise Library is a collection of application functionality blocks that you can re-use in your application for common functionality you'd otherwise have to write again and again. Here Jay Hilyard explains how to use them.

Jay Hilyard

MSDN Magazine September 2006

{ End Bracket }: Creating a Custom Metrics Tool


Metrics play an important role in our lives. Even if we don't realize it or characterize it as such, many daily activities have the potential to be quantified to some degree. So it's not surprising that metrics play an even greater role in the workplace, where there are goals and a bottom line and where much of a day's activity can be summarized in numbers.

Stephen Toub

MSDN Magazine April 2005

Error Handling: Throwing Custom Exception Types from a Managed COM+ Server Application


Exception handling semantics in .NET are based on type, so you can create custom exceptions that have their own properties and methods. In .NET, exceptions are first-class citizens, and since they're the built-in error handling mechanism, all .NET-compliant languages must support exceptions. In addition, COM+ services are available to .NET code as Enterprise Services, so you can leverage exceptions in your Enterprise Services design.In this article the author describes custom exceptions, throwing exceptions across COM interop boundaries, and working with Enterprise Services.

Bob DeRemer

MSDN Magazine March 2004

Creating a custom column with a link to document (other than the name field) in document library



I have a document library with the standard name column linking to the document. However, we'd like to create a custom field and have that link to the document (and edit item menu).

How is this best accomplished?

Thanks in advance!


To create a custom control and type while creating a column


HI All,

i am creating a column in the list while creating a column i will have an option for choice field on selecting choice i can see dropdown, radiobutton, Checkbox to select and  can enter list of values. and on clicking ok i will get a column with radiobutton. in newform.aspx and also in editform.aspx

so i need to create the similar functionality with my custom radio button, so on create column i need to show my custom choce on selecting this i need to show my custom radiobutton  and  can enter list of values then on selecting it then click ok to create a column, in edit form and new form i need to show a radio buttons with values.

Thanks in advance




Creating Custom SharePoint 2010 Field Types and Controls with Visual Studio 2010 and Silverlight 3

Learn how developers can create rich experiences in SharePoint Server 2010 publishing sites using Microsoft Silverlight 3.

Video: Creating Custom SharePoint 2010 Field Types and Controls with Visual Studio 2010 and Silverli

Watch the video that accompanies the MSDN article and learn how developers can create rich experiences in SharePoint Server 2010 publishing sites using Microsoft Silverlight 3.

Creating List Definitions with Custom List Columns for SharePoint Server 2007

Learn to use Visual Studio 2008 Extensions for Windows SharePoint Services to create a SharePoint list definition that implements custom list columns.

Video: SharePoint 2010: Creating Custom Service Applications

Do you need more than the services provided by SharePoint? In this advanced session targeted at high-end developers, you will learn how to create a custom SharePoint service. (Length: 36:31)

Video: Creating Custom Ranking Models in SharePoint 2010 Search

In SharePoint search you can tune the weighting that search uses for the results and create custom ranking models to return the results the user is expecting. (Length: 2:28)

Creating a Validator class for a custom activity

I created a new Workflow Activity Library and then added a new Activity called BindForm2Activity. After that I added a new class called BindForm2Validator and then placed an attribute to the BindForm2Activity to link it to the validator class.   Here is the code for each of the classes:   BindForm2Activity.xoml.cs: Code Snippet   using System;using System.ComponentModel;using System.ComponentModel.Design;using System.Collections;using System.Drawing;using System.Linq;using System.Workflow.ComponentModel.Compiler;using System.Workflow.ComponentModel.Serialization;using System.Workflow.ComponentModel;using System.Workflow.ComponentModel.Design;using System.Workflow.Runtime;using System.Workflow.Activities;using System.Workflow.Activities.Rules; using FormsCollection;using Utils; namespace ActivityLibrary{    [ActivityValidator(typeof(BindForm2Validator))] public partial class BindForm2Activity : SequenceActivity {        public static DependencyProperty FormToBindProperty = System.Workflow.ComponentModel.DependencyProperty.Register("FormToBind", typeof(FormsCollection.Form2), typeof(BindForm2Activity));         [Description("Form to bind a datasource to it ")]        [Category("BindForm2ToDataSource")]        [Browsable(true)]        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]        public FormsCollection.Form2 Form

Creating a custom drop down field type with SelectedIndexChanged Event

Hi All, I am trying to create a custom drop down field type and I was able to acheive that using the MS link http://msdn.microsoft.com/en-us/library/bb861799.aspx. As per the link, once the custom field is created we can override the "Validate" method to write the Validation logic and that works fine for me too. However I am facing a challenge even before going to Validate . Let me explain my actual requirements here. I need to build a custom drop down field and expose the field to the user in "Edit Properties " Page of a document library. Along with this field, I will be having some OOB site columns in the Edit Properties Page (Ex: Title, Subject etc)  . When user selects a value in the drop down, I need to hide/show few OOB site columns based on certain criteria.  I am facing a challenge of how to capture the "SelectedIndexChanged " event for the Custom drop down field in Sharepoint (Can we wire the SelectedIndexChanged event to a custom dropdown field type) ? Is this acheivable in SP 2010 Custom field type ? If so, how can I do it ? Can any of you kindly help me here?   Regards, Yesh

Creating Custom Business Connectivity Services Connectors Using SharePoint Server 2010

Learn how to create a Business Connectivity Services (BCS) custom connector to integrate data sources into SharePoint Server 2010.

Creating a new root Site Collection using a custom site definition file (ONET.XML)

Using Powershell, I am trying to deploy the our custom solution to SP 2010.  The script is doing the following: Deleting the web application using Remove-SPWebApplication Creating a new web application using New-SPWebApplication Adding and deploying a series of WSP files (one of which has the site definition file in it) using Add-SPSolution and Install-SPSolution Create a root site collection based on the site definition file provided in the WSPs using New-SPSite I get the error "WARNING: Template is not found and is not applied." When I run Get-SPWebTemplate, my site definition does not show up. I saw this: http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/5ea46e07-a4b0-4bab-b698-9b6eeb695607 but I want a solution that does not involve me reloading a DLL, as, I feel there is something else I am forgetting. I have also tried: IISReset Resetting the timer service Cleaning the Cache (as described here: http://support.microsoft.com/kb/939308) Nothing seems to work.  Does anyone have any ideas?

Pass exception details to custom error page.

Hi All, I created a custom error page and update using webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, CustomErrorPage). Its working fine and my custom error page is show if error is occurred. OR We redirect using SPUtility.RedirectToErrorPage("my message"); But I am not able to find my exception details at my custom error page. Is there any way to pass the exception details and other custom information to custom error page?  

Help with creating graphs in a site page from figurative data in custom list

Guys Can anyone provide me with someone help please? I need to be able show a graphs/line format in a web part of a site page on my SP 2010 site. I want to use some changing figurative data that is contained within a custom list change a the line/pie chart graph on the fly that is located within a chart/line graph in a site page. Basically when the data in the custom list gets changed by my resources I want to be able to see the changes in the graph almost like a live dashboard. I would be very greatful for some help. Note: I am not a coder nore do I ever claim to be, but if I could get a step by step guide on how to achieve this then I would be very greatful. I have a good understanding of SP but I am not to the coder. I able to supply the list if necessary and if someone could provide me with the code/or if code is not necessary for this task then please can you advise how? Many Thanks Mike Gowlett PMP P2P (MCSE, MSP, Old School :-) 

Creating Custom ASP.NET Control for use on a SharePoint 2010 OOTB WebPart

I am currently trying to develop a custom asp.net control that can be deployed to SharePoint 2010 and then included on something like a New item form. I have been able to build the control as part of a webpart but it needs to be done as a stand alone control that can be used on various webparts including the out of the box webparts like the WebPartPages:DataFormWebPart. Are there any good examples of building a custom control, deploying it to SharePoint and then using SharePoint designer to add that control to an existing web part?
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