Updating webparts in the GAC without using IISReset

Retirado de Michael Christensen

When deploying new versions of Webparts to the GAC, the general recommendation is to subsequentially run IISReset, since Sharepoint will not reload GAC-dlls as it would, had they been deployed to /bin.

However, for a production system this is a bit drastic (as it will cause all users to experience the dreaded “Service Unavailable” while IIS restarts), so I have been looking for alternatives.

It turns out that in order to reload a GAC-dll, all that is needed is to force an application pool recycle for the application pool Sharepoint is running within (default is MSSharePointPortalAppPool).
This can be accomplished using the MMC, or by running the following script (useful for webpart installers).

Option Explicit
‘*** spsapppoolrecycle.vbs
‘*** Script to recycle Sharepoint Portal Server application pool
‘*** For use when deploying updated version of Webparts in the GAC
 ‘*** Provided AS IS with no warranties
 ‘*** http://tinyurl.com/4k26n
Const WEBSITEID = 1
Dim objApp
Dim AppPoolId
Dim objAppPool
Set objApp = GetObject(“IIS://localhost/w3svc/” & WEBSITEID  & “/root”)
AppPoolId = objApp.AppPoolId
WScript.Echo “AppPoolID: ” & AppPoolId
Set objAppPool = GetObject( “IIS://localhost/w3svc/AppPools/” + AppPoolId )
objAppPool.Recycle()
WScript.Echo “AppPool recycled.”

Generate INSERT scripts for any table

Retirado de : DotnetSpider
 
 
 
 

/*—————————————————————————————————————————————————————————————————————————————
AUTHOR KARTHIK
DESCRIPTION BUILDS THE INSERT QUERY FOR ANY GIVEN TABLE
—————————————————————————————————————————————————————————————————————————————*/
CREATE PROCEDURE SP_GEN_INSERT_SQL  
@TABLENAME VARCHAR ( 2000 )
AS
BEGIN

DECLARE CUR_METADATA CURSOR FOR
SELECT NAME , XTYPE
FROM SYSCOLUMNS
WHERE ID IN ( SELECT ID FROM SYSOBJECTS WHERE NAME = @TABLENAME )
/* DECLARE VARIABLES*/
DECLARE @QRY1 VARCHAR (8000 ) /* Has column names */
DECLARE @QRY2 VARCHAR ( 8000 ) /* Has column values */

DECLARE @COLNAME VARCHAR ( 8000)
DECLARE @COLDATATYPE TINYINT
DECLARE @PRVCOLDATATYPE TINYINT

DECLARE @CHARPREFIX VARCHAR ( 5 )
DECLARE @CHARPOSTFIX VARCHAR ( 5 )
DECLARE @COLUMNSEPARATOR CHAR ( 1 )
DECLARE @NULLCHAR CHAR ( 4 )

SET @CHARPREFIX = ””
SET @CHARPOSTFIX = ””
SET @COLUMNSEPARATOR = ‘,’
SET @NULLCHAR = ‘NULL’

/* Start building the query */
SET @QRY1 = “SELECT ‘INSERT INTO ” + @TABLENAME + “(” –+ ” VALUES ( “

SET @QRY2 = ”

OPEN CUR_METADATA

FETCH NEXT FROM CUR_METADATA INTO @COLNAME , @COLDATATYPE

WHILE @@FETCH_STATUS = 0
BEGIN
/* Add the Column names to the query */
SET @QRY1 = @QRY1 + @COLNAME + ‘,’

/* Add Column values – Prefix & postfix the column values with quotes if they belong to any of the following datatypes */
/* TEXT – 35 | SMALLDATETIME – 58 | DATETIME – 61 | NTEXT – 99 | VARCHAR – 167 | CHAR – 175 | NVARCHAR – 231 | NCHAR – 239  */
IF ( @COLDATATYPE = 35 ) OR ( @COLDATATYPE = 58 ) OR ( @COLDATATYPE = 61 ) OR ( @COLDATATYPE = 99 ) OR
( @COLDATATYPE = 167 ) OR ( @COLDATATYPE = 175 ) OR ( @COLDATATYPE = 231 ) OR ( @COLDATATYPE = 239 )
BEGIN
IF @QRY2 = ”
BEGIN
SET @QRY2 = @QRY2  + @CHARPREFIX  + @CHARPREFIX  + @CHARPREFIX + ‘+ISNULL(CAST(‘ + @COLNAME + ‘ AS VARCHAR),’ +  “‘NULL'” + ‘)’ –+ “”)”
END
ELSE
BEGIN
SET @QRY2 = @QRY2   + @CHARPREFIX  + @CHARPREFIX  + @CHARPREFIX +  ‘+ISNULL(CAST(‘ + @COLNAME + ‘ AS VARCHAR),’ +  “‘NULL'” + ‘)’ –+ “”)”
END
SET @QRY2 = @QRY2 + ‘+’ + @CHARPOSTFIX + @CHARPOSTFIX + @CHARPOSTFIX + @COLUMNSEPARATOR
END
ELSE /*If the column is a number dont prefix/postfix quotes */
BEGIN
SET @QRY2 = @QRY2  + ”” +  ‘+ISNULL(CAST(‘ + @COLNAME + ‘ AS VARCHAR),’ +  “‘NULL'” + ‘)’
SET @QRY2 = @QRY2 + ‘+’  + @CHARPOSTFIX + @COLUMNSEPARATOR
END
–PRINT @QRY2
SET @PRVCOLDATATYPE =  @COLDATATYPE
FETCH NEXT FROM CUR_METADATA INTO @COLNAME , @COLDATATYPE
END

CLOSE CUR_METADATA
DEALLOCATE CUR_METADATA

SET @QRY1 = SUBSTRING ( @QRY1 , 1 , LEN ( @QRY1 ) – 1 )
SET @QRY1 = @QRY1 + ‘)VALUES(‘  –+ “‘” + “‘” +”‘”

SET @QRY2 = SUBSTRING ( @QRY2 , 1 , LEN ( @QRY2 )  – 1 )
SET @QRY2 = @QRY2 + ‘)’ + @CHARPOSTFIX
SET @QRY2 = @QRY2 + ‘ FROM ‘ + @TABLENAME

/* Create a temporary table to hold the result of the query – i.e. it will have the INSERT statements */
CREATE TABLE #SQLTRACE ( SQL VARCHAR ( 8000 ) )
–print  @QRY1 + @QRY2
SET @QRY2 =  ‘ INSERT INTO #SQLTRACE ‘  + @QRY1 + @QRY2
IF LEN ( @QRY2 )  < 8000
BEGIN
SET NOCOUNT ON
–PRINT @QRY2
EXEC ( @QRY2 )
–PRINT  ‘ INSERT INTO #SQLTRACE ‘  + @QRY1 + @QRY2
–EXEC ( ‘ INSERT INTO #SQLTRACE ‘  + @QRY1 + @QRY2 )
UPDATE #SQLTRACE SET SQL = REPLACE ( SQL , “‘NULL'” , @NULLCHAR )
SELECT * FROM #SQLTRACE
END
ELSE
BEGIN
PRINT ‘UNABLE TO GENERATE INSERT STATEMENTS FOR TABLE :’ +@TABLENAME
END
SET NOCOUNT OFF
END /* END OF FILE */

Using Ajax.NET under SharePoint


Retirado de :
Angus Logan

I’m having a play with Ajax.NET because I have some somewhat unique requirements from an application which is delivered under SharePoint.

The requirement is that a process may take 1 hour to complete and the process progress is being stored in a database which must be queried.

So what my plans to do are create a Web Part which looks in the DB for these processes and refresh and image and the UI to display progress – but all without a page refresh.

Ajax.NET is the perfect solution.

When I put the CSharpSample under /_layouts/ and make the initial call:

Ajax.Utility.RegisterTypeForAjax(typeof(WebUserControl1));

I get a cast exception.

Message: Specified cast is not valid

StackTrace: at Ajax.Utility.RegisterCommonAjax() at Ajax.Utility.RegisterTypeForAjax(Type t) at CSharpSample.WebUserControl1.Page_Load(Object sender, EventArgs e) in c:\program files\common files\microsoft shared\web server extensions\60\template\layouts\csharpsample\webusercontrol1.ascx.cs:line 20

The way around this is – don’t make the RegisterTypeForAjax  call!

So you need to manually include the Ajax.NET client side references (bolded below)

Control Language=”c#” AutoEventWireup=”false” Codebehind=”WebUserControl1.ascx.cs” Inherits=”CSharpSample.WebUserControl1″ TargetSchema=”http://schemas.microsoft.com/intellisense/ie5″%>

Control Language=”c#” AutoEventWireup=”false” Codebehind=”WebUserControl1.ascx.cs” Inherits=”CSharpSample.WebUserControl1″TargetSchema=”http://schemas.microsoft.com/intellisense/ie5″%>

<script type=”text/javascript” src=”/_layouts/CSharpSample/csharpwrapper/common.ashx”>/B>script>

<script type=”text/javascript” src=”/_layouts/CSharpSample/csharpwrapper/CSharpSample.WebUserControl1,CSharpSample.ashx”>/B>script>

 

<scriptlanguage=”javascript”>

function GetTime()

{

      // Make the client side to server side call

      var res = WebUserControl1.GetPercentageComplete();

     

      // Get the value and set the width of the image      

      document.getElementById(‘progress1’).width=res.value;

 

      // TODO: Handle the 100% complete response (hide the table)   

 

      // Repeat the call every 1 second

      setTimeout(‘GetTime()’, 1000);

}

FONT color=maroon>script>

<tablewidth=”100″style=”border: solid 1px black;” cellpadding=”0″ cellspacing=”0″>

      <tr>

            <td><img src=”/_layouts/CSharpSample/images/blackpixel.gif” height=”15″ width=”0″ id=”progress1″>/FONT>td>

      /FONT>tr>

FONT color=maroon>table>

The code behind then looks like:

[Ajax.AjaxMethod]

public int GetPercentageComplete()

{

      // Go get the Percentage complete (right now just seconds)

      return(System.DateTime.Now.Second);

}

 

Other than that – Ajax.NET looks awesome.

Installing Templates on the Portal

 

Retirado de : http://www.spsfaq.com/downloads/SPS_cheat_sheet_1.doc

 

For templates to available form the “Create Site” link in the Sites Directory, in other words, to create a top level site or site Collection, this must be done from the Portal command line interface. First, copy your new site template to the C: drive of the server:

 

From here http:///sites/newsite (Your New Site) go to Site Settings | Site Administration | Manage site Template Gallery right-click the .stp file and save it to the server C: drive.

 

Now go to Start | Run… and enter cmd and click OK. Type cd then past in the following path (you have to right-click and select paste, CTRL+V will not work)
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\BIN

 

 Then paste on the following

 

stsadm -o deletetemplate -title “New Site Template of Your Choice”

 

Then type IISRESET

 

This will delete the existing template, if there is one. Now Paste in:


stsadm.exe -o addtemplate -filename c:\newsite.stp -title ” New Site Template of Your Choice ”

 

Then type IISRESET again.