Today I get error in my OLAP Excel reports on SharePoint:

image

 

Continue this – http://it-club.in.ua/personal/sbelskiy/blog/Lists/Posts/Post.aspx?ID=224

Advertisements

Hi. You can create simple project Visual Studio 2010 and you have to add Event Receiver for one library. And you have to insert this code:

try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{

properties.Web.Site.CatchAccessDeniedException = false;

properties.Web.AllowUnsafeUpdates = true;

//SPFolder oFolder = properties.Web.GetFolder(properties.ListItem.Folder.Name);
//SPFileCollection collFile = oFolder.Files;
string filepath = Path.GetTempPath() + properties.ListItem.File.Name.ToString();
CopyTempFolder(filepath, properties.ListItem.File);

string workingDir = Environment.GetEnvironmentVariable("Temp") ?? Path.GetTempPath();
string sharepointBin = @"C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\BIN";
string stsadmPath = Path.Combine(sharepointBin, "stsadm.exe");

Process process = new Process();
process.StartInfo.FileName = stsadmPath;
process.StartInfo.WorkingDirectory = workingDir;
process.StartInfo.Arguments = string.Format("-o uploadformtemplate -filename {0}", filepath);
process.Start();
process.WaitForExit();

FormsService localFormsService;
SPFarm localFarm = SPFarm.Local;

bool t = localFarm.CurrentUserIsAdministrator(true);

localFormsService = localFarm.Services.GetValue<FormsService>(FormsService.ServiceName);
//ConverterMessageCollection verifyMessages;
//verifyMessages = FormTemplateCollection.VerifyFormTemplate(solutionPath);

//FormTemplateCollection collection = localFormsService.FormTemplates;
//FormTemplate formtemplate = new FormTemplate();

//formtemplate = collection.ItemFromFile(solutionPath);

SPSite site = new SPSite(properties.WebUrl);

foreach (FormTemplate form in localFormsService.FormTemplates)
{
if (form.DisplayName == properties.ListItem.DisplayName)
{
string wait = form.FormTemplateStatus.ToString();
while (wait != "Normal")
wait = form.FormTemplateStatus.ToString();
//properties.ListItem["Form Name"] = form.DisplayName;
//properties.ListItem["Form ID"] = form.FormId;
//properties.ListItem.Update();
form.Activate(site);
break;
}
}

});

}

catch (Exception ex)
{
SPUtility.TransferToErrorPage("Ошибка при публикации шаблона форм. Дополнительные сведения – " + ex.Message.ToString());
}

And you can create method CopyTempFolder.

private void CopyTempFolder(string filepath, SPFile oFile)
{
FileStream fs = null;
byte[] binfile = oFile.OpenBinary();
try
{
fs = new FileStream(filepath, FileMode.Create, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(binfile);
bw.Close();
}
catch (Exception ex)
{
SPUtility.TransferToErrorPage("Ошибка при загрузке файла шаблона форм. Дополнительные сведения – " + ex.Message.ToString());
}
}

And you have to create last method for restart al TimeJobs

private void ExecuteJobDefinitions()
{
if (SPFarm.Local.TimerService.JobDefinitions != null)
{
foreach (SPJobDefinition job in
SPFarm.Local.TimerService.JobDefinitions)
{
try
{
job.Execute(SPServer.Local.Id);
}
catch { }
}

}
}

You can see original post this – http://it-club.in.ua/personal/sbelskiy/blog/Lists/Posts/Post.aspx?ID=223