Wednesday, February 20, 2013

Clear Visual Studio Cache

Visual Studio Cache

I was getting an error Element UpdatePanel is not a known element, also intellisense was not working in the aspx designer for ajaxcontrol toolkit controls

The fix: Close Visual Studio, delete the schema cache, and re-open Visual Studio. You
can find the schemas under something like:

%appdata%\Microsoft\VisualStudio\10.0\ReflectedSchemas

Please note that the AppData folder is invisible, so it can be accessed by navigating to the C:\Users\UserName folder and then type \AppData\Roaming\Microsoft\VisualStudio\ in front of it.

It is safe to delete all files in this folder.


refered from this post
http://forums.asp.net/t/1646008.aspx/1


Component Cache

Also there is a component cache used for designers (like user control designer). If this cache is invalid then user gets an error message like
The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) Sequence contains no matching element
Resulting in: An exception occurred while calling the 'OnImportsSatisfied' method on type 'Microsoft.VisualStudio.SharePoint.Designers.Package.ViewModels.PackageViewModel'.

To clear this cache

  1. Close Visual Studio IDE
  2. Delete the folder %localappdata%\Microsoft\VisualStudio\12.0\ComponentModelCache 
  3. Repair Visual Studio Installation from Add/Remove Programs

BDC Entities

On another note, while deploying BDC entities I faced a problem because of caching in visual studio.
To clear this cache delete files in

  1. %Temp%\VWDWebCache
  2. %LocalAppData%\Microsoft\WebsiteCache
  3. %LOCALAPPDATA%\Microsoft\VisualStudio\11.0\Designer\ShadowCa‌​che
  4. Deploy SharePoint features using PowerShell rather than visual studio

More information about the issue can be found here:

http://stackoverflow.com/questions/520593/how-do-you-clear-your-visual-studio-cache-on-windows-vista
http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/6c042390-0782-4afe-94be-9746d75f5d34/
http://www.stuartroberts.net/index.php/2010/12/01/visual-studio-caching/

Language Dependency

When I used workaround mentioned in the last post above, I got an error

Invalid option '3' for /langversion; must be ISO-1, ISO-2 or Default

The issue here is Visual Studio has language dependency on ISO-1 or ISO-2. To change change language dependancy of VS project follow the steps mentioned here:

http://stackoverflow.com/questions/6460310/how-to-remove-language-dependency-in-vs-2010


TFS Cache

Clear files in %LocalAppData%\Microsoft\Team Foundation\1.0\Cache


These are some more links which discuss different scenarios when clearing visual studio cache might be necessary.
MSDN blog
http://blogs.msdn.com/b/jamesway/archive/2011/05/23/sharepoint-2010-clearing-the-configuration-cache.aspx

http://weblogs.asp.net/psheriff/archive/2011/11/08/clean-up-after-visual-studio.aspx

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe /resetuserdata

Monday, February 18, 2013

To make a user controls property visible in aspx intellisense and properties window add below attributes
 
[Browsable(true)]
       
[EditorBrowsable(EditorBrowsableState.Always)]

       
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

       
[Bindable(true)]
Sharepoint 2010 multiple file attachments
http://www.c-sharpcorner.com/uploadfile/Freddy_Khalaf/multiple-attachment-custom-control-in-sharepoint/
http://newoinc.wordpress.com/2012/03/19/sharepoint-2010-attach-multiple-files-to-a-list-item/
https://www.nothingbutsharepoint.com/sites/eusp/pages/sharepoint-list-attachment-technical-brief.aspx
http://gilleslauwers.wordpress.com/2011/02/21/sharepoint-2010s-upload-multiple-documents-in-silverlight-part-1/

Finally I have used below solution
http://www.codeproject.com/Articles/24271/Multiple-File-Upload-User-Control

But since I wanted to separate out control styles in a css file, I have modified the GetJavaScript method as below




 

JavaScript.Append(
"var Item = document.createElement('div');\n");


// *** List item inline style ***


//JavaScript.Append("Item.style.backgroundColor = '#ffffff';\n");


//JavaScript.Append("Item.style.fontWeight = 'normal';\n");


//JavaScript.Append("Item.style.textAlign = 'left';\n");


//JavaScript.Append("Item.style.verticalAlign = 'middle'; \n");


//JavaScript.Append("Item.style.cursor = 'default';\n");


//JavaScript.Append("Item.style.height = 20 + 'px';\n");

JavaScript.Append(
"var Splits = IpFile.value.split('\\\\');\n");

JavaScript.Append(
"Item.innerHTML = Splits[Splits.length - 1] + ' ';\n");

JavaScript.Append(
"Item.value = IpFile.id;\n");

JavaScript.Append(
"Item.title = IpFile.value;\n");

JavaScript.Append(
"Item.className = 'fileitem';\n");


//JavaScript.Append("debugger;\n");


//JavaScript.Append("var A = document.createElement('a');\n");



JavaScript.Append(

"var A = document.createElement('div');\n");

JavaScript.Append(
"A.innerHTML = 'Delete';\n");

JavaScript.Append(
"A.id = 'A_' + Id++;\n");


//JavaScript.Append("A.href = '#';\n");


//JavaScript.Append("A.style.color = 'blue';\n");

JavaScript.Append(
"A.className = 'linkdiv';\n");



JavaScript.Append(

"A.onclick = function()\n");

JavaScript.Append(
"{\n");

JavaScript.Append(
"DivFiles.removeChild(document.getElementById(this.parentNode.value));\n");

JavaScript.Append(
"DivListBox.removeChild(this.parentNode);\n");

JavaScript.Append(
"if(MAX != 0 && GetTotalFiles() - 1 < MAX)\n");

JavaScript.Append(
"{\n");

JavaScript.Append(
"GetTopFile().disabled = false;\n");

JavaScript.Append(
"BtnAdd.disabled = false;\n");

JavaScript.Append(
"}\n");

JavaScript.Append(
"}\n");

JavaScript.Append(
"Item.appendChild(A);\n");


// *** List item on mouse over function ***


//JavaScript.Append("Item.onmouseover = function()\n");


//JavaScript.Append("{\n");


//JavaScript.Append("Item.bgColor = Item.style.backgroundColor;\n");


//JavaScript.Append("Item.fColor = Item.style.color;\n");


//JavaScript.Append("Item.style.backgroundColor = '#C6790B';\n");


//JavaScript.Append("Item.style.color = '#ffffff';\n");


//JavaScript.Append("Item.style.fontWeight = 'bold';\n");


//JavaScript.Append("}\n");


// *** List item on mouse out function ***


//JavaScript.Append("Item.onmouseout = function()\n");


//JavaScript.Append("{\n");


//JavaScript.Append("Item.style.backgroundColor = Item.bgColor;\n");


//JavaScript.Append("Item.style.color = Item.fColor;\n");


//JavaScript.Append("Item.style.fontWeight = 'normal';\n");


//JavaScript.Append("}\n");

JavaScript.Append(
"return Item;\n");

JavaScript.Append(
"}\n");

           



 
And here are the css classes

linkdiv



{


color:Blue;


display:inline;


text-decoration:underline;

}


linkdiv:hover



{


color:Blue;


display:inline;


text-decoration:underline;

}


div.linkdiv

{


color:Blue;


display:inline;


text-decoration:underline;

}


div.linkdiv:hover



{


color:Blue;


display:inline;


text-decoration:underline;


cursor:pointer;

}


div.fileitem

{


display:block;



}


div.fileitem:hover



{


display:block;


background-color:#AEAEFF;

}


Thursday, February 14, 2013

Friday, February 8, 2013

I had a project with prebuil.bat to automatically generate entity objects for the sharepoint site.
Then I added a list template with "Create list instance for this template" set to true, thus after deploying the solution, a list instance was automatically created, but after deleting this template from the project and deploying the solution again I got the error

Feature {Guid} for list template '10000' is not installed in this farm.  The operation could not be completed

I realised that this error is because list template for the custom list is not longer valid, but I was not able to delete the list either from "All Site Contents" page or from "Site Setting -> Content and Structure" page. After digging a bit on internet and giving it a thought, I simply restored the list template from recycle bin, removed prebuild.bat command from project properties and deployed the solution again. The solution deployed without any error and I was able to delete the list instance, remove list template from my solution and deploy it back safely.

Thursday, February 7, 2013

Javascript intellisense was not working in visual studio environment. The project already had a reference to ajaxcontroltoolkit, after searching on web for nearly an hour I got below walkthrough by microsoft which works like miracle :) Wish they had added this intellisense by default, after all I just wanted to see simple dom objects like document.getElementById()

Add reference to ajaxcontrol toolkit to your project and add below code at top of the page

<asp:ScriptManager ID="ScriptManager1" runat="server">
  <Scripts>
    <asp:ScriptReference Path="JScript.js" />
  </Scripts>
</asp:ScriptManager>

Also, to automatically complete highlighted word in intellisense uncheck Tools -> Options -> Text Editor -> JScript -> Miscellaneous -> Only use tab or enter to commit.


Reference: http://msdn.microsoft.com/en-us/library/vstudio/bb385674(v=vs.100).aspx

Tuesday, February 5, 2013

Log errors to event log


try{
      
//Your method code here
}
catch (Exception ex)
{
SPDiagnosticsService.Local.WriteEvent(0, new SPDiagnosticsCategory("My Error Category", TraceSeverity.Unexpected,
EventSeverity.ErrorCritical), EventSeverity.ErrorCritical, ex.Message, ex.StackTrace);
}
Log errors to event log


try{
      
//Your method code here
}
catch (Exception ex)
{
SPDiagnosticsService.Local.WriteEvent(0, new SPDiagnosticsCategory("My Error Category", TraceSeverity.Unexpected,
EventSeverity.ErrorCritical), EventSeverity.ErrorCritical, ex.Message, ex.StackTrace);
}

Monday, February 4, 2013

To insert guid in table in sql server use
CONVERT(uniqueidentifier, 'AE019609-99E0-4EF5-85BB-AD90DC302E70'),

reference: http://stackoverflow.com/questions/959826/inserting-guid-into-sql-server

Secure micro services using jwt and ocelot

  Secure Microservices Using JWT With Ocelot in .NET Core (code-maze.com)