Tuesday, October 7, 2008

"File not found error..." whenu click on Layouts folder files..

ASP.Net Config Tool and MOSS 2007



Today our SharePoint server raised a nice exception: ‘File not Found’ when you tried to log on. Off course we were already familiar with the sound exceptions SharePoint raises so we inspected the event log.
Error: Failure in loading assembly: Microsoft.SharePoint.Portal, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
Error: Failure in loading assembly: Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c

The solution was pretty forward, but raises the question how compatible is Microsoft with Microsoft…..

It seems that when you modify the web.config with the ASP.Net Configuration Tool, it adds an attribute (xmlns) to the <configuration> tag like so: <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
so remove the attribute (xmlns) now thwe site would work.

Programatticaly Upload a document to Sharepoint List

Content of Design File:









Content Of Code File:


protected void Button1_Click(object sender, EventArgs e)
{
byte[] contents;
SPSite sp = new SPSite("");
SPWeb site = sp.OpenWeb();
site.AllowUnsafeUpdates = true;
SPList list = site.Lists["Test"];
SPListItem myNewItem;

string strDate = System.DateTime.Now.Date.TimeOfDay.ToString();
myNewItem = list.Items.Add();
string fileName = File1.Value.Substring(File1.Value.LastIndexOf("\\") + 1);

string strFilepath = File1.Value.ToString();
StreamReader sr = new StreamReader(strFilepath);
Stream fStream = sr.BaseStream;
contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
myNewItem["Title"] = "Sendil";


myNewItem.Attachments.Add(fileName, contents);
myNewItem.Update();
// System.IO.File.Delete(strFilepath);---> Deleting a source file.......
}

Tuesday, September 23, 2008

Programatically Accessing Report Folders & their Report in C#

This post is for accessing Report folder names and correspoinding reports(.rdl files) in Reporting Serbices via C# code.

1. Add a web Reference of the url http:///ReportServer/ReportService.asmx
Name it as ReportingService2005 (my convention)
2. import
using ReportingService2005;
3.

ReportingService2005.ReportingService rs;

rs = new ReportingService2005.ReportingService();
rs.Credentials = new System.Net.NetworkCredential("", "", "");
CatalogItem[] items = rs.ListChildren("/", false);
foreach (CatalogItem item in items)
{
CatalogItem[] items_rdl = rs.ListChildren("/"+item.Name, false);
foreach (CatalogItem i in items_rdl){
i.Name.ToString()
}
}

Note :
First foreach would display all report foldernames.
Second foreach would display all rdl files in first step forders.

Monday, September 22, 2008

Programatically Passing Parameter to Reporting Service in C#

using System.Collections.Generic;


ReportViewer1.ShowCredentialPrompts = false;
ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials("username", "MyPassword", "domain");
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://testuser/Reportserver");
ReportViewer1.ServerReport.ReportPath = "/Report Project State/Report1";
List parameters = new List();
parameters.Add(new ReportParameter("state", DropDownListStates.SelectedItem.Text));
ReportViewer1.ServerReport.SetParameters(parameters);
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPromptAreaButton = false;
ReportViewer1.ServerReport.Refresh();