FB_init

Showing posts with label Microsoft. Show all posts
Showing posts with label Microsoft. Show all posts

Monday, November 05, 2012

SharePoint - Displaying list items with line breaks

This is how you can display list items that have line breaks (based on SharePoint 2010)

1- With SharePoint Designer, open the site and the list.
2- Under the 'Forms' section, open 'DispForm.aspx'.
3- Find the section below and add the fragments in bold:


<asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" id="onetidPageTitleAreaFrameScript">
if (document.getElementById("onetidPageTitleAreaFrame") != null)
{
document.getElementById("onetidPageTitleAreaFrame").className="ms-areaseparator";
}

// Custom below:
$(document).ready(function() {    
     //var content = $(".ms-rtestate-field").find('div').html();
     $('DIV.ms-rtestate-field').each(function(index) {
        var innerdiv= $(this).find('div');
        if(innerdiv) {
           innerdiv.wrap('<pre/>');
        }
 });
   });

</script>
</asp:Content>



4- Save

Note: to check if the list items are really storing the newline characters, you may use a CAML Query Builder.

Friday, August 03, 2012

Basic notions of Multi-Channel Commerce Server Foundation


·         Entities are units of data structures and are declared in MetadataDefinitions.xml with the CommerceEntity element.
·         Entities have relationships to other Entities. Relationships are declared with the Relationships element.
·         An operation acts on an entity to query, create, update or delete instances. Operations are processed by Foundation’s only service entry point: the ProcessRequest method.
·         An operation may have related operations. Related operations declare sub-operations to be applied to the relationships of the base entity. For example, there can be an update operation on a Basket with a related operation to create a line item.
·         An operation with its related operations may be conceived as a tree of operations to be executed by Foundation.
·         Given the main Entity of an operation, one finds exactly one operation sequence responsible for actually executing the requested operation. Operation sequences are declared in ChannelConfiguration.config. For example, the operation sequence responsible for Basket queries is declared in
·         An operation sequence is made of a sequence of Components. Components are units of execution. Components frequenty work with the Commerce Server Core API.
·         Components work to create the result of an operation sequence. The result of an operation sequence is one or more Entities, each with its relationships to other Entities.

Reference: Multi-Channel Commerce Foundation Introduction, in Commerce Server 2009 R2: 



Monday, November 21, 2011

My daily SharePoint frustration - XXI

Scenario: in a site with both forms and NTLM authentication, a user would add a List View Web Part to the page. The user would try to delete a document from it and an error appeared on the browser:



The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.


What I tried:
  I tried to add this to the custom master page (just before the closing form tag):



        

It didn't work. I saw no difference in the source html. And I noticed that the form digest information was always there, regardless.
  I also tried to add to the existing code behind of the custom master page:

  protected override void OnInit(EventArgs e)
        {
            if (Page.IsPostBack) // custom stuff 
           {
                Microsoft.SharePoint.Utilities.SPUtility.ValidateFormDigest();
            }

It didn't work.

I tried to remove my customized master page and to use an out-of-the-box SharePoint master page. The problem was still there. I then tried to use an out-of-the-box page layout. The problem was still there. I tried to create a brand new out-of-the-box web application. The problem was not there. I then went back to web site where the problem was happening and began to comment out the http modules in web.config - trying different combinations to isolate the HTTP module. And I zoomed in to one module. I also changed the order of the http modules. Still, the same http module was the one.
Even after I found the faulty http module, it was not easy to isolate the problem.  I had to comment out the different conditions until I isolated SPContext.Current. 

Solution:

( It depends on your environment... It may not be applicable to you )  
Changing the HTTP module so that the evaluation of SPContext.Current only happens after the verification that the current handler is a Page. :

   public class MyMengaoModule : IHttpModule

        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute +=
            new EventHandler(ContextPreRequestHandlerExecute);
        }

        void ContextPreRequestHandlerExecute(object sender, EventArgs e)
        {
            Page page = HttpContext.Current.CurrentHandler as Page; // new stuff

            if (page == null)
            {
                return;
            }

            if (SPContext.Current != null && SPContext.Current.Site != null && SPContext.Current.Site.Zone == SPUrlZone.Internet) // as it was before
            ...

Time it took me to fix the problem: 3 days of work...


Monday, November 14, 2011

My daily SharePoint frustration - XX

(With SharePoint 2010)

The actions:
 - I edited a page to add a document library to it. When I tried to click on an item's menu (the ECB), I got an error dialog  saying "This item is no longer available. It may have been deleted by another user. Click 'OK' to refresh the page. "

I tried different things:

  - I couldn't use SharePoint Designer. It failed to edit any page in my case. So I couldn't follow these instructions to substitute ListViewWebPart  with XSLTListViewWebPart.

- I changed the code and assigned the website's ID to ListViewWebPart.WebID. That made no difference for me. (It worked for some other people. Probably because the underlying problem is different).

- I installed this hotfix: http://support.microsoft.com/kb/2405789 . It didn't work.

What worked for me was to edit the web part and uncheck some options (not sure exactly which one):

- Toolbar type: None (this alone may do the trick)
- Checked Enable Asynchronous Load, Enable Asynchronous Update, Show Manual Refresh Button and Enable Asynchronous Automatic Refresh.
- I unchecked Enable Data View Caching.

Thursday, September 30, 2010

My daily SharePoint frustration - XIX

This error happened with SharePoint Server 2010.

The error:


********** ERROR: The template you have chosen is invalid or cannot be found.

STACK:    at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
   at Microsoft.SharePoint.Library.SPRequest.ApplyWebTemplate(String bstrUrl, String bstrWebTemplateContent, Int32 fWebTemplateContentFromSubweb, Int32 fDeleteGlobalListsWithWebTemplateContent, String& bstrWebTemplate, Int32& plWebTemplateId)
   at Microsoft.SharePoint.SPWeb.ApplyWebTemplate(String strWebTemplate)
   at Microsoft.SharePoint.Administration.SPSiteCollection.Add(SPContentDatabase database, SPSiteSubscription siteSubscription, String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, String quotaTemplate, String sscRootWebUrl, Boolean useHostHeaderAsSiteName)
   at Microsoft.SharePoint.Administration.SPSiteCollection.Add(SPSiteSubscription siteSubscription, String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, Boolean useHostHeaderAsSiteName)
   at Microsoft.SharePoint.Administration.SPSiteCollection.Add(String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, Boolean useHostHeaderAsSiteName)
[...]

What I was trying to do: 
  I was trying to create a site collection with a custom template.

The cause of the problem:
   I was following some instructions from internal documentation on how to localize the site. One step instructed me to copy the site template XML file from the English directory to 

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LCID\XML
  
  After I deleted the XML files from both English and Japanese sites, the problem went away. I didn't try to delete just from the Japanese directory.


Friday, August 20, 2010

PowerShell listing web sites

And here is a PowerShell script to list web sites.

 Import-Module WebAdministration

while($true) {
    Write-Host '--- - - - '
   Get-Item IIS:\Sites\* | Select-Object -property Name,State
    Write-Host ' ******** '
    Start-Sleep -s 20  
  }
 





Thursday, March 25, 2010

Get a product in 5 lines of code

Here is how you can retrieve a product (in this case in a virtual catalog) in Microsoft Commerce Server (2009, but using 2007 API and not Foundation) with PowerShell in 5 lines:


[reflection.assembly]::loadwithpartialname(“Microsoft.CommerceServer.Catalog”)
$catalogAgent = new-object -typename Microsoft.CommerceServer.Catalog.CatalogServiceAgent -argumentlist (“http://localhost/DefaultSite_CatalogWebService/CatalogWebService.asmx”)
$catalogContext = [Microsoft.CommerceServer.Catalog.CatalogContext]::Create($catalogAgent)
$catalog = $catalogContext.GetCatalog("MyVirtualCatalog")
$product = $catalog.GetProduct("AW099-15(Adventure Works Catalog)")

Wednesday, February 24, 2010

Debugging T-SQL with Visual Studio

I wanted to debug a stored procedure today in T-SQL. Using VS 2008 and SQL Server 2008. I followed the instructions on MSDN but it didn't work. I read the troubleshoot guide  but it sounded too complex. A comment by a community member helped me:

"3. In Server Explorer, right-click the database object to be debugged and select Step Into Stored Procedure. Set all the desired parameters and press OK.
4. This opens up the script in the VS2008 debugger, with the code pointer at the first executable line. Set breakpoints and debug your T-SQL as you would any other file in VS2008."


However, Visual Studio was exiting the debug mode because it was constructing a SQL statement with incorrect syntax. I tried to escape some parameters but it didn't work. I created a new stored proc in the database with no params calling target stored proc with hardcoded params. Choosing 'Step Into Stored Procedure' from VS then worked. I could step into the target stored proc.

Thursday, October 01, 2009

How to use the DnsQuery function (Windows Server 2008 R2)

There's a nice article on Microsoft's Support web site titled "How to use the DnsQuery function to resolve host names and host addresses with Visual C++ .NET" ( here ). The problem is that the signature of the DnsQuery Function has changed. The first argument takes a PCTSTR instead of a char * type.
I decided to rewrite the application using PCTSTR. Here's the new version:


#include //winsock
#include //DNS api's
#include //standard i/o
#include

//Usage of the program
void Usage(char *progname) {
fprintf(stderr,"Usage\n%s -n [HostName|IP Address] -t [Type] -s [DnsServerIp]\n",progname);
fprintf(stderr,"Where:\n\t\"HostName|IP Address\" is the name or IP address of the computer ");
fprintf(stderr,"of the record set being queried\n");
fprintf(stderr,"\t\"Type\" is the type of record set to be queried A or PTR\n");
fprintf(stderr,"\t\"DnsServerIp\"is the IP address of DNS server (in dotted decimal notation) ");
fprintf(stderr,"to which the query should be sent\n");
exit(1);
}


char* WChar2char(wchar_t * src, char * ppDest) {
size_t convertedChars = 0;
size_t origsize = wcslen(src) + 1;
wcstombs_s(&convertedChars, ppDest, origsize, src, _TRUNCATE);
return (char*)ppDest;
}

void Char2Wchar(char* src, wchar_t * ppDest) {
size_t convertedChars = 0;
size_t origsize = strlen(src) + 1;
mbstowcs_s(&convertedChars, ppDest, origsize, src, _TRUNCATE);
}

void ReverseIP(wchar_t* pIP)
{
wchar_t seps[1]; seps[0] = (wchar_t)'.';
wchar_t *token;
char pIPSec[4][4];
int i=0;
token = wcstok( pIP, seps);
while( token != NULL )
{
/* While there are "." characters in "string" */
sprintf(pIPSec[i],"%s", token);
/* Get next "." character: */
token = wcstok( NULL, seps );
i++;
}
swprintf(pIP,L"%s.%s.%s.%s.%s", pIPSec[3],pIPSec[2],pIPSec[1],pIPSec[0],"IN-ADDR.ARPA");
}


// the main function
void __cdecl main(int argc, char *argv[])
{
DNS_STATUS status; //Return value of DnsQuery_A() function.
PDNS_RECORD pDnsRecord; //Pointer to DNS_RECORD structure.
PIP4_ARRAY pSrvList = NULL; //Pointer to IP4_ARRAY structure.
WORD wType; //Type of the record to be queried.
wchar_t pOwnerName[255]; //Owner name to be queried.
wchar_t pReversedIP[255]; //Reversed IP address.
wchar_t DnsServIp[255]; //DNS server ip address.
DNS_FREE_TYPE freetype ;
freetype = DnsFreeRecordListDeep;
IN_ADDR ipaddr;
char * chOwnerName = NULL;

if(argc > 4) {
for(int i = 1; i < argc ; i++) {
if ( (argv[i][0] == '-') || (argv[i][0] == '/') ) {
switch(tolower(argv[i][1])) {
case 'n':
//pOwnername=
chOwnerName = argv[++i];
Char2Wchar(chOwnerName, (wchar_t *) pOwnerName);
break;
case 't':
if (!stricmp(argv[i+1], "A") )
wType = DNS_TYPE_A; //Query host records to resolve a name.
else if (!stricmp(argv[i+1], "PTR") )
{
//pOwnerName should be in "xxx.xxx.xxx.xxx" format
if(wcslen(pOwnerName)<=15)
{
//You must reverse the IP address to request a Reverse Lookup
//of a host name.
swprintf(pReversedIP,L"%s",pOwnerName);
ReverseIP(pReversedIP);
size_t sizeRev = wcslen(pReversedIP) + 1;
wcsncpy_s(pOwnerName, sizeRev, pOwnerName, 255);
//pOwnerName=pReversedIP;
wType = DNS_TYPE_PTR; //Query PTR records to resolve an IP address
}
else
{
Usage(argv[0]);
}
}
else
Usage(argv[0]);
i++;
break;

case 's':
// Allocate memory for IP4_ARRAY structure.
pSrvList = (PIP4_ARRAY) LocalAlloc(LPTR,sizeof(IP4_ARRAY));
if(!pSrvList){
printf("Memory allocation failed \n");
exit(1);
}
if(argv[++i]) {
wchar_t aarray[300];
Char2Wchar(argv[i], (wchar_t*)aarray);
wcscpy(DnsServIp,aarray);
char tmp[500];

pSrvList->AddrCount = 1;
pSrvList->AddrArray[0] = inet_addr(WChar2char(DnsServIp, (char*) tmp)); //DNS server IP address
break;
}

default:
Usage(argv[0]);
break;
}
}
else
Usage(argv[0]);
}
}
else
Usage(argv[0]);

// Calling function DnsQuery to query Host or PTR records
status = DnsQuery(pOwnerName, //Pointer to OwnerName.
wType, //Type of the record to be queried.
DNS_QUERY_BYPASS_CACHE, // Bypasses the resolver cache on the lookup.
pSrvList, //Contains DNS server IP address.
&pDnsRecord, //Resource record that contains the response.
NULL); //Reserved for future use.

if (status){
if(wType == DNS_TYPE_A)
printf("Failed to query the host record for %s and the error is %d \n", pOwnerName, status);
else
printf("Failed to query the PTR record and the error is %d \n", status);
} else {
if(wType == DNS_TYPE_A) {
//convert the Internet network address into a string
//in Internet standard dotted format.
ipaddr.S_un.S_addr = (pDnsRecord->Data.A.IpAddress);
printf("The IP address of the host %s is %s \n", pOwnerName,inet_ntoa(ipaddr));

// Free memory allocated for DNS records.
DnsRecordListFree(pDnsRecord, freetype);
}
else {
printf("The host name is %s \n",(pDnsRecord->Data.PTR.pNameHost));

// Free memory allocated for DNS records.
DnsRecordListFree(pDnsRecord, freetype);
}
}
LocalFree(pSrvList);
}




(keywords: DNS, DnsQuery, Windows Server 2008 R2 )