Tuesday, December 4, 2012

ERROR - There are no Content Types in the project.

When you are trying to create a new list definition based on a content type that you have defined in your project you are getting this error.

When you have put a SharePoint Project in to a Solution Folder, Visual Studio 2010 loses its ability to locate your SPI’s in your project. The solution you can use to fix this issue is move the project out of the solution folder, add your list and move the project back into the solution folder.

Tuesday, July 10, 2012

Fixing the button disabled issue after download a file in a custom web part in SharePoint2007.

After you download a file from custom web part in a SharePoint 2007 site, normally all the buttons and link buttons are disabled and click events are not working. So here is a simple fix for that. Copy and paste the fallowing script in the bottom of your web part.

<script type="text/javascript">
_spOriginalFormAction = document.forms[0].action;
_spSuppressFormOnSubmitWrapper = true;
</script>

Friday, March 23, 2012

Textbox watermark using jquery

<html>
<head>
<title></title>
<style type="text/css">
.gray
{
color: Gray;
}
.black
{
color: Black;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function () {
$("#txtDate").val("dd/mm/yyyy").addClass("gray");
$("#txtDate").focus(function () {
if ($("#txtDate").val() == "dd/mm/yyyy") {
$("#txtDate").val("").addClass("black").removeClass("gray");
}
});
$("#txtDate").focusout(function () {
if ($("#txtDate").val() == "") {
$("#txtDate").val("dd/mm/yyyy").addClass("gray").removeClass("black");
}
});
});
</script>
</head>
<body>
<input id="txtDate" type="text" />
</body>
</html>

Thursday, March 22, 2012

Convert a file to a byte array

///
/// Function to get byte array from a file
///

/// File name to get byte array
/// Byte Array
public byte[] FileToByteArray(string fileName)
{
byte[] buffer = null;

try
{
// Open file for reading
System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);

// attach filestream to binary reader
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fileStream);

// get total byte length of the file
long totalBytes = new System.IO.FileInfo(fileName).Length;

// read entire file into buffer
buffer = binaryReader.ReadBytes((Int32)totalBytes);

// close file reader
fileStream.Close();
fileStream.Dispose();
binaryReader.Close();
}
catch (Exception exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", exception.ToString());
}

return buffer;
}

JavaScript Browser Detection

Sometimes it can be useful to detect the visitor's browser, and then serve the appropriate information.
The Navigator object contains information about the visitor's browser name, version, and more.

Sample Code :

<html>
<head>
<script language="javascript" type="text/javascript">
function browserDetect() {
var browserType;

if(/chrome/.test( navigator.userAgent.toLowerCase() )){
browserType="chrome";
}
else if(/webkit/.test( navigator.userAgent.toLowerCase() )){
browserType="safari";
}
else if(/opera/.test( navigator.userAgent.toLowerCase() )){
browserType="opera";
}
else if(/msie/.test( navigator.userAgent.toLowerCase() )){
//browserType="msie";
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
browserType="msie " + ieversion;
}
}
else if(/mozilla/.test( navigator.userAgent.toLowerCase() )){
browserType="mozilla";
}
else
{
browserType="none of these - chrome,safari,opera,msie,mozilla";
}

alert(browserType);

}
</script>
</head>
<body>
<a href="javascript:browserDetect();">Detect Browser</a>
</body>
</html>