Friday, 3 March 2017

asp.net mvc core image handler

It's a while since my last blog , today i am gonna write an asp.net mvc image handler (Middle-ware) with following assumptions:

  1. asp.net mvc core web application based on .net framework/.net core
  2. NuGet package for resize images Magick.NET-Q16-AnyCPU
  3. Image Manager in code used to get Image by id (replace it with your code)
  4. Image will be stored in Database (Binary + MimeType)
  5. Url will be {SiteUrrl}/images?id=xx&h=xx&y=xx
  6. id is image id in database
  7. h image height
  8. w image width


Step 1:Create ImageMiddleware class
Step 2:Create ImageMiddlewareExtensions class
Step 3:Register ImageMiddleware class in startup class



Source Code (Links on GitHub):
ImageMiddleware Class
ImageMiddlewareExtensions


Then in your startup class Add:

 app.UseImageMiddleware("/images");


Testing:
My site url is : http://localhost:14600

http://localhost:14600/images?id=12&w=150&h=150






http://localhost:14600/images?id=12&w=400&h=400















Wednesday, 23 December 2015

Value does not fall within the expected range - SharePoint Client Object Model


While working on SharePoint 2013 client object model to upload files to servers i have received the following error:

Value does not fall within the expected range Sharepoint

UploadLayoutsPageBase: Microsoft.SharePoint.Client.ServerException: Value does not fall within the expected range.  
 at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)  
 at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()


Solution:

If you are using full file path , make sure not to add any extra slash

Valid :   http://10.151.0.67:8010/sites/docs_1/Contact/20/photo_v1.jpg
Invalid : http://10.151.0.67:8010//sites/docs_1/Contact/20/photo_v1.jpg


Some people saying that you have to give relative file URL not full path , for me i used to give full path and it's working very well.



Value does not fall within the expected range  is a common error just like sorry something went wrong , please try again later.

Thursday, 23 April 2015

Sharepoint2013 Adding Editor Style



SharePoint 2013 enables you to add specific styles to your custom CSS
that can be accessed through the ribbon and used by content authors on your site



  • Font Face—The font face used on the selected text.
  • Font Size—The size of the selected text.
  • Highlight Color—Background color behind the selected text. 
  • Font Color—The selection text color. 
  • Styles Page Element—An HTML element will be injected around the        selection and a style will be applied to that element.
  • Styles Text Style—A specific style will be applied to the selection.






/*--Font Face--*/
.ms-rteFontFace-SECFontFace {
-ms-name: "SEC Font";
font-family: 'Comic Sans MS';
}

/*--Font Size--*/
.ms-rteFontSize-SECFontSize {
font-size: 25px;
}

/*--Highlight Color--*/
.ms-rteBackColor-SECBackColor {
background-color: #25408f;
-ms-name: "";
-ms-color: "SEC Blue";
}

/*--Font Color--*/
.ms-rteForeColor-SECForeColor {
color: #e98013;
-ms-name: "";
-ms-color: "SEC Orange";
}

/*--Styles - Page Element--*/
DIV.ms-rteElement-SECElement {
-ms-name: "SEC Element";
}


.ms-rteElement-SECElement {
border: 1px solid #e98013;
}

/*--Styles - Text Styles--*/
.ms-rteStyle-SECStyle {
-ms-name: "SEC style";
color: #e98013;
font-size: 25px;
}


After that you will see the Font in Editor as in below image:





Monday, 22 December 2014

SharePoint List Query Throttling NOT Apply number of results returned by your query

Important note you may not know:


What Is Query Throttling (different meaning)?
The list view threshold does not apply simply to the number of results returned by your query. Instead, it restricts the numbers of database rows that can be accessed in order to complete execution of the query 


What does it mean?
suppose you are working with a list that contains 10,000 items. If you were to build a query that returns the first 100 items sorted by the ID field, the query would execute without issue because the ID column is always indexed. However, if you were to build a query that returns the first 100 items sorted by a non-indexed Title field, the query would have to scan all 10,000 rows in the content database in order to determine the sort order by title before returning the first 100 items. Because of this, the query would be throttled, and rightly so—this is a resource-intensive operation.








Monday, 8 September 2014

SharePoint Repository Pattern Step By Step

This Post has been in my agenda for sometime but finally i got the time to write it:

I have done a lot of work with SharePoint API in my career path , and each time i see this code i become upset and feel angry even i  wrote this code many times :


             using (SPSite  site = new SPSite(path))
                {
                    using (SPWeb  web =  site.OpenWeb())
                    {
                          //Do work
                    }
              }


Problem:

Project  Solution (SPRepository)  will  consist of  three Projects:
  1. SPRepository.Core (class library): contains the Repository 
  2. SPRepository.Domin (class library) : Reference the (1) contains all entities 
  3. SPRepository.Portal (SharePoint Project). Reference  (1 and 2) and contains web parts(UI)




SPRepository.Core (class library): 


The class diagram for (SPRepository.Core) as below image (Figure1) 
Two weeks ago (today 3/10/2013) my manger asked me to make some changes on online Portal.
I got shocked on seeing hundreds of repeated codes.

I went to Google and start searching (sharepoint document repository).
But i didn’t find what i wants so i start reading and assembly parts to come up with complete solution that might help me and help others,
Of course i got some idea from other blogs.
Let's start talking about the Solution:


 Figure 1



Description of Class Diagram
class EntityBase
Is the base class of each entity  also please note that the entity represent SPList and contains the common Fields in SPList (ID , Title , Modified , Created, ModifiedBy , CreatedBy)


interface IMapper<TEntity>
Is the mapper that converts an entity of type (EntityBase) to and from SPListItem.
Its convert and SPListItem to EntityBase and vice versa


interface IRepository<TEntity>
contains all method that we need to work with SPList like Query , getting item and update item(SPListItem)


class Repository<TEntity> is the real implementation for IRepository<TEntity>

Let’s start by real example:

We have Department SPList with Fields
  1.    ID
  2.          Title
  3.           DeptCode

Also We have SPList called Employee with fields:
  1.                ID
  2.              Title
  3.               FirstName
  4.    LastName
  5.              Department (Lookup filed)





We will start by building Entity objects in the Project (SPRepository.Domin)
Add new class called Department inherited from Class EntityBase
and add Properties: (DeptCode , don't add other Properties because it's already in the base class EntityBase).



Add new class called Employee inherited from Class EntityBase
and add Properties:























 Okay don't upset it's very easy , we will start n example showing  step by step to how we can use the repository.




To be continue...

if you interested drop a comment











Friday, 5 September 2014

ajax error syntaxerror json parse unexpected token Jsonresult

I want Load Subcategories based on selected category using JQuery Ajax or JSON , on asp.net MVC application. 

Problem:
I've upgraded to VS.NET 2013, and now, every time I receive error when getting subcategories for category .

Error:jqXHR: 200textStatus: parser errorerror Thrown: SyntaxError: Unexpected token 


some solutions on internet was changing dataType:json or remove dataType and removing the content Type .. ,  i tried every possible solution with no luck.


after 4 hours of trying to solve the problem .i created on page with 2 dropdownlists only without master page, when i open HTML source code i found this line of code.


<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Chrome","requestId":"ac71e2a7594e4504a5135609483e8c7a"}
</script>
<script type="text/javascript" src="http://localhost:8157/eb9f5c3c339d488fb419a027dfa861bd/browserLink" async="async"></script>
<!-- End Browser Link -->



This is script is interfering with JQuery  library  and it crashes the jQuery reference.

this code came from new feature in visual studio 2013 called  Browser Link
After i disabled it the error went and every thing work as expected.





to disable it:




















Friday, 15 August 2014

A java Runtime Environment (JRE) or Java Development kit (JDK) must be available in order to run Eclipse

A java Runtime Environment (JRE) or Java Development kit (JDK) must be available in order

to run Eclipse. No Java virtual machine was found after searching the following locations:

 C:\eclipse\jre\javaw.exe javaw.exe in your current PATH



To solve this issue:

Download JAVA 64bit from this url http://www.java.com/en/download/manual.jsp