How To Cancel And Remove Certain Files When Using Telerik RadAsyncUpload



TODO:

Have you ever wanted to remove certain files, when using RadAsyncUpload control in multi select mode?  The problem is, you calling cancelUpload in the Uploading event cancels all uploads.  That is not idea for obvious reasons.

 

SOLUTION:

var errorFiles = '';

//OnClient Uploading Event
function onClientFileUploading(sender, args) {

     //if some condition is met, then cancel the upload, and add the filename to a variable.
     alert('alert user possibly that file will be removed');

     //cancel the upload
     args.set_cancel(true);

     //add to error list, we will need to remove in the Uploaded event...as it still fires.
     errorFiles = errorFiles + currentUploadedFilename.toUpperCase() + '|';
}

//OnClient Uploaded Event
function onClientFileUploaded(sender, args) {
     //create array of file names
     var filename = errorFiles.split("|");
     var count = filename.length;
     
     //process each filename
     $.each(filename.reverse(), function (key, item) {
          if (args.get_fileName().toUpperCase() == item.toUpperCase()) {
               //remove click
               $telerik.$(".ruRemove", args.get_row()).click();
               filename[key] = '';
               return;
          }
     })
     errorFiles = '';
     $.each(filename.reverse(), function (key, item) {
          if (item.length > 0) {
               errorFiles = errorFiles + item.toUpperCase() + '|';
          }
     })
}

 

NOTES:

This snippet of code, will allow you to choose files to cancel during the upload process, and then automatically remove them from the list of documents automatically.

How To Use A Telerik RadGrad In PopUp Mode For Inserts, And InPlace For Edits



TODO:

Have you ever wanted to use a popup window for inserts to a Telerik RadGrid, but then allow editing to be done InPlace?

 

SOLUTION:

protected void rgdDocuments_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
     if (e.CommandName == RadGrid.EditCommandName)
     {
          rgdDocuments.MasterTableView.EditMode = GridEditMode.InPlace;
     }
     if (e.CommandName == RadGrid.InitInsertCommandName)
     {
          rgdDocuments.MasterTableView.EditMode = GridEditMode.PopUp;
     }
}


NOTES:

There are no notes on this topic.

How To Convert A List To A Delimited String



TODO:

Have you ever wanted to take a List<string> and convert it into a delimited string?

 

SOLUTION:

string someString = "test1.txt|test2.txt|test3.txt;
//split the string on | to get a List<string>
List<string> files = someString.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>();

//now flatten it to a delimited string
string newValue = string.Join("|", files.Select(x => x).ToArray());

 

NOTES:

There are no notes on this topic

How To Get The Current SharePoint User That Is Logged In Using C#



TODO:

Have you ever wanted to get the current user that is logged into SharePoint?

 

SOLUTION:

//set textfield to the user
txtModificationBy.Text = this.Web.CurrentUser.LoginName;

 

NOTES:

There are no notes on this topic.

How To Use BulkCopy To Insert A DataTable In C#



TODO:

Have you ever wanted to insert the contents of a DataTable efficiently using SqlClient.BulkCopy?

 

SOLUTION:

public static void FillMonteCarloSimulationResults(DataTable InDataTable)
{
     using (SqlBulkCopy bulkCopy = new SqlBulkCopy("myconnectionstring")
     {
          //***NOW Do column mappings.  This maps columns from DataTable (left) to DB Table (right)
          bulkCopy.DestinationTableName = "Results";
          bulkCopy.ColumnMappings.Add("EmployeeId", "EmployeeId");
          bulkCopy.ColumnMappings.Add("Name", "Name");
          bulkCopy.WriteToServer(InDataTable);            
     }
}

 

NOTES:

This example will take the DataTable, map the columns, then preform BulkCopy

How To Fix "Could not load file or assembly '$SharePoint.Project.AssemblyFullName$" Error When Adding HttpHandler To SharePoint Application Project



 

TODO:

You add a HTTPHandler to your SharePoint project, and  you get the following error : "Parser Error Message: Could not load file or assembly '$SharePoint.Project.AssemblyFullName$' or one of its dependencies. The system cannot find the file specified."

  

SOLUTION:

The fix is simple, do the following:

1.  Open your project file in NotePad

2.  Find the PropertyGroup nodes.

3.  Add a new PropertyGroup node.

<PropertyGroup>

     <TokenReplacementFileExtensions>ashx;</TokenReplacementFileExtensions>

 </PropertyGroup>

4.  Re-Open your project file


NOTES:

There are no notes on this topic.

How to Change Application Page Title Dynamically In C# Code Behind



TODO:

Have you ever wanted to change the title of your Application Page dynamically?

 

SOLUTIONS:

protected void SetPageTitles(string Title)
{
     ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderPageTitle");
     contentPlaceHolder.Controls.Clear();
     LiteralControl title = new LiteralControl();
     title.Text = Title;
     contentPlaceHolder.Controls.Add(title);

     contentPlaceHolder = (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderPageTitleInTitleArea");
     contentPlaceHolder.Controls.Clear();
     title = new LiteralControl();
     title.Text = Title;
     contentPlaceHolder.Controls.Add(title);
}

 

NOTES:

There are no notes on this topic.

Causes And Fixes For "Error: Sys.ArgumentNullException: Value cannot be null." In JQuery



TODO:

You make some changes the ASP.net controls on your form, and possible your JQuery.  You run your application and you end up with "Error: Sys.ArgumentNullException: Value cannot be null."  

 

SOLUTION:

95% of the time I have had this issue, the problem was that I removed a control, and its references in the .cs file, but forgot it in the JQuery.  So in the JQuery I was doing a .hide() on the removed control which causes the cryptic error above.  To debug I simply looked for each instance of $('#mycontrolxxxxxxx').hide(); and made sure that #mycontrolxxxxxxx actually still existed.  Sure enough, I forgot to remove a JQuery line.  Once I removed the rogue JQuery line, the issue went away. 

 

NOTES:

There are no notes on this topic.

How To Disable The Enter Key Using JQuery



TODO:

Have you ever wanted to disable the enter key for your entire form, including "modal" edit popup windows for the Telerik RadGrid?  If so, put this code in the document.ready function, and the Enter key will no longer submit your form data.

 

SOLUTION:

$(document).ready(function() {
        //disable the enter key, it causes too many issues....
        //Bind this keypress function to all of the input tags
        $('input').live('keypress', (function (evt) {
             //Deterime where our character code is coming from within the event
             var charCode = evt.charCode || evt.keyCode;
             if (charCode == 13) { //Enter key's keycode
                  return false;
             }
        }));

        //OR USE THE ONE BELOW.  ONE ABOVE WORKED BEST FOR ME
    function checkKeyPress(e) {
        if (e.keyCode == 13) {

            if (!e) var e = window.event;

            e.cancelBubble = true;
            e.returnValue = false;

            if (e.stopPropagation) {
                e.stopPropagation();
                e.preventDefault();
            }
        }
    }
    $("input").keydown(checkKeyPress);
})‚Äč

 

NOTES:

Method 1 worked for me, but I have seen method 2 used before also.

How To Secure Sharepoint Application Pages By User Group



TODO:

Have you ever wanted to secure an Sharepoint Application Page by User Group?  If so, just use the method below, and call it in Page_Load.

 

SOLUTION:

/// <summary>
/// Validate that the page can be accessed
/// </summary>
/// <returns></returns>
protected void ValidatePageAccess(string[] AllowedUserGroups)
{
     try
     {
          //get web object
          using (SPWeb currentWeb = this.Web)
          {                    
               #region Allowed Groups

               SPGroup allowedGroup = null;
               bool userHasAccess = false;

               //check each, if one group is OK, all are.
               foreach (string group in AllowedUserGroups)
               {
                   allowedGroup = currentWeb.Groups[group];

                   //see if user is in allowed group
                   if (allowedGroup.ContainsCurrentUser)
                   {
                       if (Request.HttpMethod == "POST")
                       {
                           SPUtility.ValidateFormDigest();
                       }
                       userHasAccess = true;
                       break;
                   }
               }
               
               //now check access
               if(!userHasAccess)
               {
                    throw new Exception("User does not have access");
               }
               #endregion 
          }
     }
     catch (Exception x)
     {
          Response.Redirect("/_layouts/accessdenied.aspx");
     }
}

 

NOTES:

There are no notes on this topic.