Tuesday, March 21, 2017

How to use the css file in the Nintex Form to customize the layout

it is quick convenient if we can have a css file to control the layout of the Nintex form, This approach will allow us to modify the change in the css file to fix all layout isse in the nintex. we did not have to open all the forms one by one and modify the css in the Custom CSS Section in the Form Setting Window




Actually we can use the Custom CSS Includes Section to add a link reference pointing to the path of the css file



we only have to refresh the page to get the change in affect. in my case, i put my css stylesheet under the style library in the same sharepoint site

Site URL/Style%20Library/CSS/AdminAccessControlForm.css










Thursday, February 16, 2017

How to force outlook download all items from exchange server after I clear all the offline emails.

I try to clear the cache to see if i can get all the emails shown in my outlook.

i right click on my inbox folder to get this popup window





then click on the clear offline itmes, then all my emails are gone from my outlook window.

I try to use update Folder button from the SEND/RECEIVE menu




but the Inbox did not load any items from exchange server.

after consult with the network administration, here is the solution

1. go the folder that store the outlook data file

C:\Users\YourUserName\AppData\Local\Microsoft\Outlook

2. rename the Outlook Data File to other name, then close the outlook and skype for business.

3. re-launch the outlook application, boom the outlook will rebuilt the outlook data file and download all the emails items from the exchange server.
















Wednesday, January 25, 2017

How to ensure the file upload succeed using CSOM in Sharepoint Add-ins development?

when we implement the file upload to sharepoint document library. we might not able to log the error from sharepoint, which will cause the the failure of file upload.

we can use the approach that return the document id after the file is uploaded to sharpeoint dcoment library. we can verify the document id to check the result of file upload. if the document id is return, it indicated that the document is successfully upload to sharpeoint. otherwise i will be failed.

here is the snipet of code to handle the above logic.

private string UploadFileToSharepoint(Byte[] fileData, string newFileName)
        {
         
            string guidId = string.Empty;
            try
            {
                var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

                using (var clientAppContext = spContext.CreateAppOnlyClientContextForSPHost())
                {
                    List list = clientAppContext.Web.Lists.GetByTitle(sListTitle);
                    FileCreationInformation newFile = new FileCreationInformation();
                    newFile.Overwrite = false;
                    using (newFile.ContentStream = new MemoryStream(fileData))
                    {
                        newFile.Url = newFileName;
                        Microsoft.SharePoint.Client.File uploadFile = list.RootFolder.Files.Add(newFile);
                        clientAppContext.Load(uploadFile, u => u.ListItemAllFields.Id);
                        clientAppContext.ExecuteQuery();
                        guidId = uploadFile.ListItemAllFields.Id.ToString();
                    }
                    return guidId;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Tuesday, January 24, 2017

How to use Select Top N Rows from DB2 Database in AS400 System

it is quite simple if you want to limit the number of records return from the query execution in SQL Server

Select top N Rows from your table..

However DB2 did not support the select Top N Rows, there is a work around function

like this

Select * from your table order by column Desc fetch first N rows only

since the fetch first N rows only will return random number of rows. we must use order by column name to enforece the same records return by sorting the column.

Wednesday, January 18, 2017

How to solve "Collection was modified; enumeration operation may not execute." in Dictionary iteration using C#

when i try to iterate through a dictionary and remove the item that had been processed.

i got a runtime error "Collection was modified; enumeration operation may not execute."

Dictionary<string, FileAttachement> tempAttachment = attachments;
tempAttachment.Remove(item.Key);

the root cause of the error is that i declause a temp variable and reference to the same objec that will iterate through. the run time process detect the change of the attachments object and throw the exeption.

we can't simply use the variable with referenced to dictionary object. we should use the deep copy or clone mechanism to get a copy of the dictionary object.

the following snipet of code will create a new object and copy the content from the dictionary object.

Dictionary<string, FileAttachement> tempAttachment = new Dictionary<string, FileAttachement>(attachments);



Thursday, January 5, 2017

a simple trigger for SQL Server Update Insert and Delete action

i show a easy way to do data auditing with trigger on an Order Table, which will allow user to update and Insert records in the Order table.

here i implement a logic to determine the user action like Update or Insert, if a record is being delete and insert then we know the record had been update, otherwise it is a straight insert

  IF EXISTS(SELECT * FROM INSERTED) AND EXISTS(SELECT * FROM DELETED)
    begin
        set @Operation='Update'
    end
   else
   begin
        set @Operation='Insert'
    end


ALTER trigger [dbo].[tblTriggerInsertUpdateAuditRecord] on [dbo].[Order]
after update, insert
as
begin
  declare @Operation nvarchar(10)
  IF EXISTS(SELECT * FROM INSERTED) AND EXISTS(SELECT * FROM DELETED)
    begin
        set @Operation='Update'
    end
   else
   begin
        set @Operation='Insert'
    end
  insert into OrderAudit
  ( OrderID
      ,OrderNumber
      ,OrderDate
      ,ShipperID
      ,ShippingCompanyID
      ,WorkStationID
      ,PaymentTermID
      ,CreateDate
      --,UpdateDate
      ,OrderStatus
      ,IsTailGateRequire
      ,AdditionalOrders
      ,TotalPieces
      ,TotalWeight
      ,Supervisor
      ,Operation )
  select  i.OrderID
      ,i.OrderNumber
      ,i.OrderDate
      ,i.ShipperID
      ,i.ShippingCompanyID
      ,i.WorkStationID
      ,i.PaymentTermID
      ,GETDATE()
      ,i.OrderStatus
      ,i.IsTailGateRequire
      ,i.AdditionalOrders
      ,i.TotalPieces
      ,i.TotalWeight
      ,i.Supervisor
      ,@Operation
  from  Order t
  inner join inserted i on t.OrderID=i.OrderID
end













In term of delete, we just need to copy a record from delete table in Temp database

ALTER trigger [dbo].[triggerDeleteAuditOrderDetails] on [dbo].[OrderDetails]
after delete
as
begin
  insert into OrderDetailsAudit
    (OrderDetailsID
      ,SCIOrderID
      ,Quantities
      ,ShipItemID
      ,IsDangerousGoods
      ,DangerousGoodsHazardClassID
      ,Weight
      ,Operation
      ,CreateDate)
  select  D.OrderDetailsID
      ,D.SCIOrderID
      ,D.Quantities
      ,D.ShipItemID
      ,D.IsDangerousGoods
      ,D.DangerousGoodsHazardClassID
      ,D.Weight
      ,'Delete'
      ,GetDate()
  From DELETED D 
end