Showing posts with label SharePoint Code. Show all posts
Showing posts with label SharePoint Code. Show all posts

Thursday, October 6, 2011

How to filter the data in data form web part using calender control


ParameterBinding Name="PFromDate" Location="Control(CalFrom,SelectedDate)" DefaultValue=""
ParameterBinding Name="PToDate" Location="Control(CalTo,SelectedDate)" DefaultValue=""


Convert the date into number (YYYYMMDD)

number(string(ddwrt:FormatDateTime(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date),1033,1)),'/','-'),1060,'yyyyMMdd'))) >= number(string(ddwrt:FormatDateTime(translate(string(ddwrt:FormatDate(string($PFromDate),1033,1)),'/','-'),1060,'yyyyMMdd'))) and number(string(ddwrt:FormatDateTime(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date),1033,1)),'/','-'),1060,'yyyyMMdd'))) <= number(string(ddwrt:FormatDateTime(translate(string(ddwrt:FormatDate(string($PToDate),1033,1)),'/','-'),1060,'yyyyMMdd')))

old: Wrong Calc
number(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1)),'/','')) >= number(translate(string(ddwrt:FormatDate(string($PFromDate), 1033, 1)),'/','')) and number(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1)),'/','')) <= number(translate(string(ddwrt:FormatDate(string($PToDate), 1033, 1)),'/',''))
new


Ref:


number(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1)),'/','')) = number(translate(string(ddwrt:FormatDate(string($PFromDate), 1033, 1)),'/',''))

ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1) >= ddwrt:FormatDate(string($PFromDate), 1033, 1) and ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1) <= ddwrt:FormatDate(string($PToDate), 1033, 1)


number(translate(string(ddwrt:FormatDate(string(@Report_x0020_Date), 1033, 1)),"/",""))

number(translate(string(ddwrt:FormatDate(string($PFromDate), 1033, 1)),'/',''))

Wednesday, October 5, 2011

How to disable the RichTextBox in SharePoint

function disableRichTextBox(ctrlComments)
{
ctrlComments.disabled=true;
ctrlComments.readOnly=true;
var elm = document.getElementById(ctrlComments.id + "_toolbar");
if (elm) {elm.disabled=true; elm.readOnly = true;elm.style.display = 'none';}
elm = document.getElementById(ctrlComments.id + "_iframe");
if (elm) {elm.disabled=true; elm.readOnly = true;elm.style.display = 'none';}
ctrlComments.style.display = 'block';
}

Monday, January 31, 2011

Delete event receiver from a SharePoint list

  1. private void DeleteEventReceiverFromAList(string siteUrl)
  2. {
  3. using (SPSite site = new SPSite(siteUrl))
  4. {
  5. using(SPWeb web = site.OpenWeb())
  6. {
  7. try
  8. {
  9. SPList list = web.Lists["myList"];
  10. if (list != null)
  11. {
  12. string className = "EventReceiverClass";
  13. string asmName = "EventReceiverAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a865f0ecc234ea51";
  14. web.AllowUnsafeUpdates = true;
  15. int receivers = list.EventReceivers.Count;
  16. bool isAddedReceiverExist = false;
  17. bool isUpdatedReceiverExist = false;
  18. for (int i = 0; i <>
  19. {
  20. SPEventReceiverDefinition eventReceiver = list.EventReceivers[i];
  21. if (eventReceiver.Class == className && eventReceiver.Type == SPEventReceiverType.ItemAdded)
  22. {
  23. eventReceiver.Delete();
  24. break;
  25. }
  26. }
  27. }
  28. }
  29. catch { }
  30. finally
  31. {
  32. web.AllowUnsafeUpdates = false;
  33. }
  34. }
  35. }
  36. }

Monday, November 15, 2010

Connection String File

1. Create a text file.
2. Change a file extension as UDL
3. Now Double Click the file and Test connection string.
4. close
5. Open a file with notepad
6. We can have connection string

Friday, November 12, 2010

Find the userId from a people picke

<script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
fields = init_fields();
// Find the userId from a people picker in DispForm
var userIdRaw = $(fields['client']).find('.ms-formbody a').attr('href');
var userId = userIdRaw.substring(userIdRaw.indexOf('=')+1);
// Here is the userId for the person in the people picker
alert(userId);

function init_fields(){
var res = {};
$("td.ms-formbody").each(function(){
if($(this).html().indexOf('FieldInternalName="')<0) return;
var start = $(this).html().indexOf('FieldInternalName="')+19;
var stopp = $(this).html().indexOf('FieldType="')-7;
var nm = $(this).html().substring(start,stopp);
res[nm] = this.parentNode;
});
return res;
}
</script>

Sunday, October 31, 2010

Adding a list item to Document library through c# in SharePoint 2007

1. string fileName = fileUpload.PostedFile.FileName;
2. using (SPSite site = new SPSite("http://sharepointserver"))
3. {
4. using (SPWeb web = site.OpenWeb("/"))
5. {
6. try
7. {
8. web.AllowUnsafeUpdates = true;
9. using (FileStream fs = File.Open(fileName, fileMode.Open))
10. {
11. SPList list = web.Lists["Documents"];
12. Hashtable metaData = new Hashtable();
13. for (int i = 0; i < keys.Count; i++)
14. {
15. metaData.Add(keys[i], values[i]);
16. }
17. SPFile destfile = list.RootFolder.Files.Add(fileName.Substring(fileName.LastIndexOf("\\") + 1),
18. fs, metaData, true);
19. if (destfile == null)
20. lit.Text = "Error in adding file";
21. }
22. }
23. catch
24. { }
25. finally
26. {
27. web.AllowUnsafeUpdates = false;
28. }
29. }
30. }