September 2008


 

We have observed in different cases, suppose we have a video file in a sharepoint library, if we click the file  it prompts for username/password. It is not very user friendly, as the password needs to be entered every time.

 

After some searches we found many people facing this problem so we suggested that we can open the video in a web page instead of opening it in Windows Media Player.

 

So, we created an aspx page in _layouts folder.

Now, whenever the user clicks to open a video file, we redirect it to the aspx page like,

 

http://gitolekha/_layouts/ad.aspx?lnk=http://gitolekha/Videos/sharepoint.wm

 

in ad.aspx we pass the name of the document library, here videos and the file name, here gito sharepoint.wm

 

here, we embed the video file in the aspx web page,

 

< OBJECT id="MediaPlayer" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">

<PARAM NAME="SRC" VALUE=<%=strVal %>>

<PARAM NAME="AUTOSTART" VALUE="1><PARAM NAME="SHOWCONTROLS" VALUE="1"><param name="ShowStatusBar" value="1">

</OBJECT >

 

strVal is the name of the file which we get from the code behind,

 

if (Request.QueryString[“lnk”] != null)

{

   string strVal = Request.QueryString[“lnk”].ToString();

}

 Our job is done, we have embedded the video file in the webpage, so it dosen’t ask for username/password every time we try to open it as it was before when we opened it in Windows Media Player.

 

Now, how to download it?

We can always download from Sharepoint document library through some coding, but I am lazy, I want to leave it to the default download system of windows as right click -&gt; save as. How do we do that?

 

On top of the webpage I give a hyperlink as shown below, now I want to stop users from left clicking so that they are forced to right click -&gt; save target as.

 

<a href=<%=strVal %>; onMouseOver=’document.onmousedown=noLeftClick’ onMouseOut=’document.onmousedown=null’><b>Download File</b></a>;

 

 

<script language=”javascript”>

function noLeftClick()

{

   if (event.button==1)

   {

    alert(‘Please use the rightclick \”Save Target As\” Command to Download’)

    }

 }

<script>

 

Now, how do users send email of the link of the video to other users?

 

We send it as shown below to the same aspx page, however we need to encode it, here filename = gito sharepoint.wmv, so while encoding it is sent as below,

 

http://gitolekha/_layouts/ad.aspx?lnkftp=ftp://174.456.12.45/CPD%20sharepoint.wmv

 

see the code below,

void emailImage_DataBinding(object sender, EventArgs e)

{

 HyperLink mailImage = (HyperLink)sender;

mailImage.NavigateUrl = “mailto:?body=” + mailImage.Page.Server.UrlPathEncode(FinalLink + “&subject=Link to “ + fileTitle);

}

 

Here final link is the link shown above(http://gitolekha/_layouts/ad.aspx?lnkftp=ftp://174.456.12.45/gito%20sharepoint.wmv

) and final title is the title to be shown in the subject line of the mail.

 

Advertisements

We know that to open a pop-up we use window.open( [sURL] [, sName] [, sFeatures] [, bReplace]).

But, what if we want to open it as a modal window? We can use window.showModalDialog(sURL [, vArguments] [, sFeatures]).

But this approach has certain disadvantages, your client side script does not always behave the way it should otherwise.

So the best possible approach to open a modal pop-up window is,

From your page, open a normal popup as
window.open(‘/_layouts/OpenOpUp.aspx?Mode=New’, ‘pop1’,‘left=80, top=50, center=yes, height=480, width=450,status= no, resizable= no, scrollbars=yes, toolbar=no, location=no,menubar=no’); 

Now, in the modal popup window(here, OpenOpUp.aspx) in the body tag write,
<body onblur=”self.focus()”>
Your job is done, now it will behave as a modal popup window as it will have focus on itself and you have to close the page to get back to the parent page (either through javascript or by clicking the cross button at top) and all your client side scripts will work just fine.

Suppose we have a xml document, now we need to search for an item in it.
We can do this using SelectSingleNode method which is used to locate an element. The SelectSingle-Node method requires an XPath query to be passed into the method. See the sample xml document below,

<?xml version=”1.0″ encoding=”us-ascii” ?>
<TreeView>
<node text=”Topics”>
<node text=”Corporate”>
<node text=”Best Places to Work”>
<node text=”Health Fairs” />
</node>
<node text=”Pharma”>
<node text=”General Medicines”>
<node text=”Arthritis “>
<node text=”Osteoporosis” />
<node text=”Oral calcitonin” />
</node>
</node>
</TreeView>

So, if I want to find an item ‘Arthritis’ in the xml document, I have to do this,

string BzFocusxmlpath = @”C:\Program Files\ BizFocus.xml”;

 

string strParentVal = “”;       

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(BzFocusxmlpath);

XmlNode node;

node = xmlDoc.SelectSingleNode(“//node[@text=‘Arthritis’]”);

string snode = node.OuterXml;

 

Now, snode will return a value <node text=\”Arthritis”><node text=\”Osteoporosis\” /><node text=\”Oral calcitonin\” /></node>
which is the value of all nodes under General medicines, so, how do we extract only “Arthritis”?
Here, some C# coding will help,

int intindex = snode.IndexOf(“>”);

string strsubstr = snode.Substring(0, intindex); //will return “<node text=\”Arthritis “”

string[] strstarray = strsubstr.Split(‘=’);

string strStoreBizVal = strstarray[1].ToString(); // will give “\”Arthritis 

string strStoreBizValParent = “”;

// For removing “\” and “/” characters from string

strStoreBizVal = strStoreBizVal.Replace(“\””, “”);

strStoreBizVal = strStoreBizVal.Trim();

if (strStoreBizVal.Contains(“/”))

{

    strStoreBizVal = strStoreBizVal.Replace(“/”, “”);

    strStoreBizVal = strStoreBizVal.Trim();

}

So, our strStoreBizVal now  contains, ‘Arthritis’.

 

Now, suppose we want the hierarchy of the item in the xml file, like,

‘Arthritis’ is under parent node ‘General Medicine’, ‘General Medicine’ is under ‘Pharma’ and that is under ‘Topics’.

So, what if we want to display the whole hierarchy as,

Topics|Pharma|General Medicines|Arthritis” ?

For this, we need to traverse the xml document to get the hierarchy of parent and child, we can do this using simple recursive C# code, refer to the above xml code where the top most node is <TreeView> so, we traverse the Parent nodes till we reach there, see below

while (node.ParentNode.OuterXml.StartsWith(“<TreeView>”) == false)

{

    strParentVal = node.ParentNode.OuterXml;

    int intindexParent = strParentVal.IndexOf(“>”);

    string strsubstrParent = strParentVal.Substring(0, intindexParent);

    string[] strstarrayParent = strsubstrParent.Split(‘=’);

    strStoreBizValParent = strstarrayParent[1].ToString();

    strStoreBizValParent = strStoreBizValParent.Replace(“\””, “”);

    strStoreBizValParent = strStoreBizValParent.Trim();

    if (strStoreBizValParent.Contains(“/”))

    {

strStoreBizValParent = strStoreBizValParent.Replace(“/”, “”);

strStoreBizValParent = strStoreBizValParent.Trim();

    }

    strStoreBizVal += “|” + strStoreBizValParent;

    node = node.ParentNode;

}

string strFinalBizVal = strStoreBizVal;

 

// Now we get “Arthritis|General Medicines|Pharma|Topics“, since we are traversing from below so the top most node appears last, so we have to reverse the string to get “Topics|Pharma|General Medicines|Arthritis

 

string strReverseBizVal = “”;

string[] strReverseBizValArr = strFinalBizVal.Split(‘|’);

for (int j = strReverseBizValArr.Length -1; j >= 0; j–)

{

    strReverseBizVal += strReverseBizValArr[j].ToString() + “|”;

}

strReverseBizVal = strReverseBizVal.Remove(strReverseBizVal.LastIndexOf(‘|’));

 

This will give me, “Topics|Pharma|General Medicines|Arthritis”

SQL Server 2005 Query Analyzer shortcuts.CTRL+E : Execute Query

F5 : Execute Query

ALT+BREAK : Cancel Query

CTRL+D : Display results in grid format

ALT+F1 : Database object info.

CTRL+F5 : Parse query and check syntax

CTRL+K : Display/hide execution plan

CTRL+L : Display execution plan

CTRL+N : New Query window

CTRL+SHIFT+F : Save results to file

CTRL+Delete : Delete through the end of the line

Some General Shortcuts

CTRL+A : Select All

CTRL+C : Copy

CTRL+V : Paste

CTRL+F : Find

CTRL+P : Print

CTRL+S : Save

CTRL+Z : Undo

CTRL+Y : Redo

CTRL+X : Delete