Wednesday, July 15, 2009

input Checkbox or Radio button with runat server and checked property

Usually, when we actually don’t need of ASP.NET controls, we will use HTML control with runat="sever" for better processing. So, if you use the input checkbox/radio button control, it has the checked attribute, by default it look for the value "checked" for checked attribute in HTML. But because we made it server-side control by adding runat="sever" to it, it won't allow the "checked" value to "checked" attribute. The possible values for it is only True or False.

<input type="radio" runat="server" id="radioTech" checked="true" />

So, instead of "checked" value, use true or false.

Blocked file types in SharePoint 2007 – Custom web services 2.0 in SharePoint 2007 – Part 3

Please read the post "Steps to implement custom web services in SharePoint" before continue here.

I think, most of the people don't know about blocked file types and where can we set them. SharePoint by default, won't allow all the file extensions because of some security issues.

Why the SharePoint team didn't allow them by default. There is a strong reason behind it. i.e. not other than Security reasons. For example, EXE extension file, script files etc.

How to remove a blocked file type?

  • Open central administration site.
  • Go to Operations tab.
  • Find a section named "Security Configuration".
  • Under this section, you can find a link for "Blocked file types".

    Blocked file types

  • On this page, you can see a text box area which displays all the file extensions one per line, which SharePoint blocked by default.

      image

  • You can edit and delete the extension. Then SharePoint allows user to upload the file or access the file.

So, if you are facing the problem of not able to upload the files of type .asmx, .exe, .chm etc.. This is the place where you set it. Happy SharePointing.

Steps to add a Web service 2.0 in SharePoint 2007

Today at my work, I need to implement JQuery in SharePoint on a module. I need to make AJAX calls to get the data from the database depending on the value in a text box. So, I choose JQuery, because I know it well and it will take very less time to implement. But for JQuery I need to create page web methods. But SharePoint doesn’t support Page web methods because SharePoint is completely built upon ASP.NET 2.0.

So, what is the solution, how can I make a call to the server and get the data from DB? After thought some time about it, finally I got a brilliant and better idea of using web services. Please follow the steps below to implement Web services in SharePoint.

  • We are using client side technologies like JQuery etc to call Web service to get the data from server. By default, it is not supported. For that, we need the supporting DLL's[System.Web.Script.Services] for the Web service script on the SharePoint server. These DLL's are needed to process the web service request and send the response[JSON]. For those DLL, you need to install the Ajax extensions 1.0.
  • Create a web service using Visual studio. It will generate two files webservice.asmx and webservice.cs. Write all the web methods required inside the webservice.cs file. I will explain you with an example more detail later in this post.
  • Now, we need a location to keep our *.cs [webservice.cs] file. So, for that, create App_Code folder in the SharePoint site file system virtual directory root [c:\inetpub\…\wss\virtualdirectories\portnumber]. You can find the advantages of using App_code folder, in SharePoint web application in this post.
  • By default SharePoint won't allow the script handlers and http modules. For this reasons, we need to make the web.config changes as explained in this post.
  • Change the settings in central admin to remove asmx extension from blocked file types. See it here.

After you are ready with all the above steps, then please follow the steps below.

  • Check the related dll’s are added in the system, after installed Ajax extensions. Below are the namespaces you required in the webservice.cs file.
  • using System.Web.Services;
    using System.Web.Script.Services;

  • Copy the webservice.asmx file to the SharePoint website virtual directory file system path [c:\inetpub\…\wss\virtualdirectories\portnumber\].
  • Copy the file webservice.cs file, and paste it in the app_code folder of the SharePoint web site.
  • Please follow the post web.config changes as explained.
  • Central administration changes as explained above.

There we are done with the process. This is really working great and we can solve really very difficult problems like all scenarios where we need to communicate with DB without doing post back etc. This is very smooth and fast way of retrieving results. I like to hear feedback. This is the one of the best solutions I found. Please post any problems if you face while implementing this process.

Isn't this a valuable find?

Custom web services in SharePoint 2007 - Web.config changes – Part 2

Please read the article "Steps to implement web service 2.0 in SharePoint" before continue this post. Then you will get some idea on what is the need of change in web.config for implementing custom web service 2.0 in SharePoint.

SharePoint framework don't allow to call web services from java script by default. For this, we explicitly tell the web application that when any request from javascript to web services then use this http handlers, http modules and allow *.asmx files to serve in SharePoint.

So, please follow the steps below.

Changes required in the sections.

  • HttpHandlers and httpModules in <System.Web> section.
  • Adding a new section named <System.WebServer>.
  • This is not needed, but useful if you have installed two versions of Ajax libraries[1.0 and 3.5] for System.Web.Extensions. Assembly binding redirect in <runtime>
  • Add  System.web.Extensions assembly to the <assemblies> section. This is very important.

Please add the sections as it is in the web.config file of your SharePoint web site to get the web services 2.0 work.

1. <httpHeaders> section:
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></httpHandlers>

2. <httpModules> section:

    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

3. <System.WebServer> section:

<system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules>
            <remove name="ScriptModule"/>
            <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </modules>
        <handlers>
            <remove name="WebServiceHandlerFactory-Integrated"/>
            <remove name="ScriptHandlerFactory"/>
            <remove name="ScriptHandlerFactoryAppServices"/>
            <remove name="ScriptResource"/>
            <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </handlers>
    </system.webServer>

4. <runtime> Section:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
            </dependentAssembly>
        </assemblyBinding>

5. <assemblies> section:

Add this entry to <assemblies> section.

<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

That’s it!!! With these changes it will allow you to access web services from java script. I spent my valuable time to find this way to solve so many problems. Do you like this?

Thursday, July 9, 2009

App_Code folder in SharePoint – Custom web services in SharePoint – Part 1

On the way of explaining the process of implementing custom web services in SharePoint, I thought of telling you the advantage of App_Code folder in SharePoint. So, Please read this post before continue here.

If you are a .NET developer then you know the advantage of App_Code folder. When I am new to SharePoint technology, I thought like we can't add App_Code folder in SharePoint root folder because i didn't find it in the virtual directory path. […/Inetpub/wwwroot/…../] But few days back, when I got time, I want to do experiment on the App_Code folder in SharePoint. So, what are the advantages and how to do it please follow below steps.

  • Go to SharePoint web site virtual directory file system path. There you can find web.config file, _app_bin, App_Browsers etc…
  • Create a folder named App_Code.
  • Copy a class file [.cs], which you want to use in SharePoint coding inside the App_Code folder.

Now, you can access this class any where in the SharePoint web site. Very useful one right?

Wow, This helped me many scenarios and really a good tactic for solving lot of problems. Try this now!!!

Wednesday, July 8, 2009

Fixing the error Permission denied to get property XULElement.selectedIndex in Mozilla Firefox

When working with Mozilla Firefox browser, I usually come across the error below many times.

Usual exception details: Permission denied to get property XULElement.selectedIndex

Error because of my own javascript function:
Permission denied to get property XULElement.popupOpen

I want to write this post because, for me it took long time to solve the issue. May be most of the people may get this error when working with Mozilla Firefox.

Why it is coming? What are the possibilities?

This will come if you are making AJAX calls with a input type text box, then firebug will throw this error. This is because it is a autocomplete functionality. To fix this what you need to do is, just add an attribute to input control as shown below.

<input type="text" autocomplete="off" />

This will stop Firefox from attempting to complete the content in the box.

That's it!!!

Is this helpful?

Microsoft.SharePoint.Upgrade.SPUpgradeException

After I installed the MOSS SP2 update yesterday, when I hit refresh on my custom ASPX page, I got the below exception.

Microsoft.SharePoint.Upgrade.SPUpgradeException: An error has occurred on the server.http://go.microsoft.com/fwlink?LinkID=96177.

I was little bit surprised and frustrated to find out the cause why it was showing. I ran the configuration wizard and checked the database schema version. Everything was fine. After research and thought about it for some time, started trail and error methods to find out the issue by going to event viewer and logs etc…

Finally found the problem. That was Because of not restarting the server after installing the SP2 on the server. After I restarted the server, everything worked fine and i am very happy by seeing the page on the browser.

Is this helpful?

Tuesday, July 7, 2009

Install language pack in SharePoint 2007

I have MOSS server running from long time and it has plenty of sites running. Now I got a new requirement from one of my clients that their site should support different languages. This bothered me somewhat because of this article. http://technet.microsoft.com/en-us/library/cc262108.aspx

Which explains as below

  • Install the necessary language files on the front-end Web servers.

  • Install Office SharePoint Server 2007 on each front-end Web server.

  • Run the SharePoint Products and Technologies Configuration Wizard on each front-end Web server.

If that is the case, I need to uninstall MOSS on the server and need to install all language files before installing MOSS. But if that happens I will loose my server settings and the whole environment. It’s impossible to get the same development settings if I uninstall it. Then I posted about this, in MSDN forums and Mike Walsh all time favorite to me, gave me very fast reply and his solution worked great!!!

You can take a look at it here.

http://social.msdn.microsoft.com/Forums/en-US/sharepointadmin/thread/1963f252-056e-43ec-8480-d99a4f8d5388

Hope this will help you too!!!

Show envelope icon in notification area – Outlook 2007

Today, I am little bit surprised that I didn’t see the envelope icon in notification area of my window Taskbar even i have unread emails in my Outlook inbox. So, as usual I thought, no new messages were in my inbox. After some time, my colleague came and asked me that why didn’t you give reply for the messages I sent. I told him that I didn’t get any. He was surprised and checked his sent items list and he was sure that mail was sent to me. Immediately I open my inbox and found couple of messages from him. That was a big shock and I didn’t believe that. Because I completely believe in the envelope symbol on the Taskbar that if any unread mail is in my inbox, it should show up there.

image

Some how the settings were changed and i started checking the tools options for getting that again. Below are the steps i followed to get it.

  • Open your Outlook.
  • Go to Tools menu, choose Options.
  • In the preference tab, you can find a section for E-mail as shown below.
  • image
  • Click on the E-mail Options button. Which will open a window for the email option.
  • Click on the Advanced E-main Options button which again opens another windows which has the option we want.
  • Select the option "Show envelope in notification area" as shown below.
  • image
  • That’s it. Now I am able to see the envelope icon in the notification area on new mail arrival.
  • image

Hope this helps for the people who faced the same problem.