About the author

Vijay Kodali
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2024

The type or namespace name 'ProjectName' could not be found (are you missing a using directive or an assembly reference?)

Problem:

If you try to add a client application to a solution containing server applications, will get this error..

Reason:

The .NET Framework 4 Client Profile was chosen as the default for client-side applications that don't require access to features like ASP.NET. Basically .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications.

Solution:

Change Target framework from ".Net Framework 4 Client Profile" to ".Net Framework 4"

 


Posted by Vijay on Thursday, February 11, 2010 9:33 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Cannot start service SPUserCodeV4 on computer – SharePoint 2010

Issue:

If you try to deploy a sandboxed solution and run into this Error

 Cannot start service SPUserCodeV4 on computer

SandboxError

 

Reason:

Microsoft SharePoint Foundation Sandboxed Code Service is not running on the server.

Solution:

Go to Central Administration -> System Settings -> Manage services on server- > “Microsoft SharePoint Foundation Sandboxed Code Service

-> click the “Start” link button to start the service.

StartSandBoxCodeService


Categories: SharePoint2010
Posted by vijay on Thursday, January 14, 2010 8:51 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Convert time from one timezone to another timezone in Asp.Net

Handling timzone is quite simple in Asp.Net applications. First thing,   you should always store DateTime values in the DB in one timezone (UTC is most commonly used).  This eliminates many conversion issues.


Here is the sample code..

DateTime time1 = new DateTime(2008, 12, 11, 6, 0, 0);  // your DataTimeVariable 
TimeZoneInfo timeZone1 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); 
TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"); 
DateTime newTime = TimeZoneInfo.ConvertTime(time1, timeZone1, timeZone2);

Get all available/supported Timezones in .Net TimeZoneInfo class

      foreach (var tz in TimeZoneInfo.GetSystemTimeZones())
            {
                Response.Write(tz.DisplayName + " is Id =','" + tz.Id + "'");
                Response.Write("<br>");
            }


Posted by Vijay on Wednesday, January 6, 2010 8:24 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Auto save Asp.net form values Asynchronously

In this article, I will explain how to save Asp.Net page values asynchronously (aka Gmail style of saving mail drafts).  

Introduction:

In the past, Web applications were known for having less usable, less responsive user interfaces. AJAX changed all of that. The application can work asynchronously and the user doesn't have to sit and wait for pages to refresh. :

What is Ajax?

Ajax (Asynchronous JavaScript and XML) is an approach to web development that uses client-side scripting to exchange data with a web server. 

Solution:

There are several ways of achieve it. In this article I am using AJAX functionality to call ASP.NET Web services from the browser by using client script. Yes, no updatepanel.  

Start by adding a web service to the project as shown below, name it as AsynchronousSave.asmx. Make this web service accessible from Script, by setting class qualified with the ScriptServiceAttribute attribute...  

[System.Web.Script.Services.ScriptService]    
public class AsynchronousSave : System.Web.Services.WebService 


Here is the AsynchronousSave webservice class: 
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class WebService2 : System.Web.Services.WebService
{

    [WebMethod]
    public string HelloWorld()
    {

        return "Hello World";

    }

    [WebMethod]
    public string SaveInput(String input)
    {
        string StrInput = Server.HtmlEncode(input); if (!String.IsNullOrEmpty(StrInput))
        {

            string[] strFields = StrInput.Split('+');

            //code to save all input values
            // you can easily savethese values to temp DB table, temp file or xml file
            //Dispaly last saved values

            return String.Format("Last saved text: FirstName {0} ,<br/> Last name {1} <br/> Last "

            + "saved draft {2} at {3}.", strFields[0], strFields[1], strFields[2], DateTime.Now);

        }

        else
        {

            return ""; //if input values are empty..retrun empty string
        }
    }
}
 
Nothing fancy here, just methods marked with [WebMethod] attribute. The Saveinput method takes an input string with “+” as delimiter between form values.  

To enable web service to be called from client side, add script manager to page  

<asp:ScriptManager runat="server" ID="scriptManager">
    <Services>
        <asp:ServiceReference Path="~/AsynchronousSave.asmx" />
    </Services>
</asp:ScriptManager>


And here is HTML of page

<div>
    First Name:<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox></br> 
    LastName:<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></br> 
    Draft :<asp:TextBox ID="txtDraft" runat="server"></asp:TextBox></br></div>
<div id="Preview">

The following example shows the java script that makes service calls

<script language ="javascript" >
    //This function calls the web service    
    function SaveUserInput() {
        var fName = document.getElementById("txtFirstName");
        var lName = document.getElementById("txtLastName");
        var draft = document.getElementById("txtDraft");
        //Saving all input in a single value         
        var input = fName.value + "+" + lName.value + "+" + draft.value;
        //ProjName.WebServiceName.WebMethod         
        SampleApplication1.AsynchronousSave.SaveInput(input, SucceededCallback);
    }
    // This is the callback function that processes the Web Service return value.     
    function SucceededCallback(result) {
        var divPreview = document.getElementById("Preview");
        divPreview.innerHTML = result;
    }
    // execute SaveUserInput for every 10 sec, timeout value is in miliseconds
    window.setInterval('SaveUserInput()', 10000); 
    
</script>

Reference:

http://msdn.microsoft.com/en-us/library/bb398998.aspx

         


Tags:
Posted by vijay on Monday, November 23, 2009 2:17 PM
Permalink | Comments (0) | Post RSSRSS comment feed

ASP.Net AJAX AsyncFileUpload Control

AsyncFileUpload is a new ASP.NET AJAX Control (Ajax Control Toolkit (v 3.0.30930) released for .NET 3.5 SP1) that allows you asynchronously upload files to server. You don’t need a separate upload button for this control.  Add the AsyncFileUpload control and a label to the web form for the uploading and displaying messages respectively.  HTML:

<asp:ScriptManager ID="ScriptManager1" runat="server"> 
</asp:ScriptManager> 
<cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" CompleteBackColor="White" 
OnUploadedComplete="AsyncFileUpload1_UploadedComplete" OnUploadedFileError="AsyncFileUpload1_UploadedFileError" 
OnClientUploadComplete="Success" OnClientUploadError="Error" /> 
<asp:Label ID="Label1" runat="server"></asp:Label> 

Server side events:

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) 
{ 
 //Fired on the server side when the file successfully uploaded 
   if (AsyncFileUpload1.HasFile) 
   { 
         AsyncFileUpload1.SaveAs(@"C:\Images\" + AsyncFileUpload1.FileName ); 
         Label1.Text = "Received " + AsyncFileUpload1.FileName + " Content Type " + AsyncFileUpload1.PostedFile.ContentType ; 
   } 
 } 
protected void AsyncFileUpload1_UploadedFileError(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) 
 { 
 //Fired on the server side when the loaded file is corrupted 
 //Display some error message here 
 } 

Client side events:

OnClientUploadError - The name of a javascript function executed in the client-side if the file uploading failed  

OnClientUploadComplete - The name of a javascript function executed in the client-side on the file uploading completed

function Success() { 
document.getElementById("Label1").innerHTML = "File Uploaded Successfully !!"; 
} 
function Error() { 
document.getElementById("Label1").innerHTML = "File upload failed"; 
} 

We can use  OnClientUploadComplete to clear fileupload control selction,

function Success() { 
document.getElementById ("Label1").innerHTML = "File Uploaded Successfully !!"; 
var fu = document.getElementById("AsyncFileUpload1"); 
document.getElementById("AsyncFileUpload1").innerHTML = fu.innerHTML; 
} 

Reference:  http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx


Posted by vijay on Friday, October 2, 2009 2:48 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Disabling script debugging in VS 2008 and IE8

With VS 2008 and IE 8, JavaScript debugging is automatically enabled even if script debugging is set to disabled in IE8 settings. This will help developers in debugging scripts without having to change debugging features within browser. While this is a good feature for most developers, it takes up to 10X time to load a page that is heavy on client side scripts. 

How to disable script debugging in IE8?

Go to a Command Prompt (cmd) and Enter… 

reg add HKLM\SOFTWARE\Microsoft\VisualStudio\9.0\AD7Metrics\Engine\{F200A7E7-DEA5-11D0-B854-00A0244A1DE2} /v ProgramProvider /d {4FF9DEF4-8922-4D02-9379-3FFA64D1D639} /f 

To enable it again go to the Command Prompt and Enter...

reg add HKLM\SOFTWARE\Microsoft\VisualStudio\9.0\AD7Metrics\Engine\{F200A7E7-DEA5-11D0-B854-00A0244A1DE2} /v ProgramProvider /d {170EC3FC-4E80-40AB-A85A-55900C7C70DE} /f 

Tip from:Gregg Miskelly of Visual Studio team debugger team


Posted by vijay on Wednesday, July 1, 2009 2:40 PM
Permalink | Comments (1) | Post RSSRSS comment feed

Check if variable is number in C#

            string s ="45";
            int i;
            bool isNum = int.TryParse(s.ToString(), out i); 
 
            if (isNum)
                Response.Write(i); //integer 
            else
                Response.Write("Not an interger");

Categories: ASP.NET | C#
Posted by vijay on Thursday, June 18, 2009 9:27 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Hide GridView AutoGenerate Columns

            //hide header column
            GridView1.HeaderRow.Cells[0].Visible = false;

            //hide column in data rows
            foreach (GridViewRow row in GridView1.Rows)
            {
                row.Cells[0].Visible = false;
            }

Categories: ASP.NET | ASP.Net 3.5
Posted by vijay on Thursday, March 26, 2009 8:37 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Visual studio Development Server problem in Vista

Problem:

Internet Explorer can not display the page.

Localhost not able to establish a connection on port..

getting the above messages when trying to run my application locally. I got this problem after installing this week's updates to Vista.  It messed up VS developer server settings. 

Apparently it was due to Definition Update for Windows Defender - KB915597 (Definition 1.53.256.0)

Solution:

Go to c:\Windows\System32\drivers\etc\ and open the file named hosts with a text editor and search for the line containing "::1"  and change "::1" to ":::1" by adding an extra ":" 

It solved the problem on one of my development machine. If it didn’t work, leave a comment.

Update:

Another solution from visual web developer team.

Update:

Same problem is discussed here and here


Posted by vijay on Thursday, March 12, 2009 1:23 PM
Permalink | Comments (42) | Post RSSRSS comment feed

Ajax AutoCompleteExtender not working

Make sure you have indicated that a Web service can be invoked from script..

 
    [System.Web.Script.Services.ScriptService]
    public class AutoCompleteService : System.Web.Services.WebService
    {
 
        //[WebMethod]
        //public string HelloWorld()
        //{
        //    return "Hello World";
        //}
    }


Categories: Ajax Toolkit | ASP.NET
Posted by vijay on Thursday, March 12, 2009 9:57 AM
Permalink | Comments (0) | Post RSSRSS comment feed