Tuesday, April 2, 2013
Easy but worth publishing.. Uploading document to Doc Library via Code..
public static void PushFileToDocLib()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("site url"))
{
using (SPWeb web = site.OpenWeb())
{
string fileToUpload = "c:\\ExcelWorkBookName.xlsx";
if (!System.IO.File.Exists(fileToUpload))
throw new FileNotFoundException("File Not Found", fileToUpload);
SPFolder docLibrary = web.Folders["Document Lib Name"];
Boolean ExistingFiles = true;
string fileName = System.IO.Path.GetFileName(fileToUpload);
FileStream fileStream = File.OpenRead(fileToUpload);
SPFile spFile = docLibrary.Files.Add(fileName, fileStream, ExistingFiles);
docLibrary.Update();
}
}
});
}
Tuesday, January 15, 2013
Enable/Disable Asp validators via Javascript..
Yes.. it is among the most fundamental functions of javascript but I admit that i didnt know about it. So i tend to share to those who sometime somewhere stands on my feet.
Ok, there is a function call ValidatorEnable(control, bool status).
This function enables/disables the validator control specified as parameter in the fucntion.
For Eg:
function ActivateValidator(Ctrl) {
alert(Ctrl.value.length);
if (Ctrl.value.length > 0) {
var myValidator = document.getElementById('<%=rfvLowTier.ClientID %>');
ValidatorEnable(myValidator, true);
} Hope this helps!
Ok, there is a function call ValidatorEnable(control, bool status).
This function enables/disables the validator control specified as parameter in the fucntion.
For Eg:
function ActivateValidator(Ctrl) {
alert(Ctrl.value.length);
if (Ctrl.value.length > 0) {
var myValidator = document.getElementById('<%=rfvLowTier.ClientID %>');
ValidatorEnable(myValidator, true);
} Hope this helps!
Subscribe to:
Posts (Atom)