|
some of your user have to print another format from A4 and you have to use CrystalDecisions.CrystalReports.Engine.ReportDocument
In you form where user gives format of paper, ur application takes that parameters.
example:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
.
.
.
ReportDocument dc = new ReportDocument();
dc.PrintOptions.PaperSize = PaperSize.PaperA5;
_____________________
Proud to be Albanian
_____________________
|
|
|
|
|
i'm a c# developer but till now i didn't know how to make adatabase using sql server and connect it with c#
i know how to do with access so f there is any ona help me stp by stp ???????????
also a crystal report i wanna know how to use it and connect it with c#
|
|
|
|
|
|
|
Here u have some samples for crystal reports...
CrystalReports
_____________________
Proud to be Albanian
_____________________
|
|
|
|
|
Hello,
I asked this question in visual studio forum too.
Is it possible to move the obj directory ? (like VC++ project)
I would like to have three different directories (on the same root) :
- binaries
- source code
- temporary (obj)
I see where are these options in VC++ project settings, but not in VC# project.
Thank you
Freg.
|
|
|
|
|
Hi
All what i can tell you ( in case if i understand you )
in the "Solution Explorer" Right click the project you are working on and highlight "Add" --> "New Folder" and Give your folder a name say "Sourc Code"
and drag and drop your files into this new folder.
Now you have a folder contain all of your source code
then right click your project once again click "Properties"
and from the "Configuration" comboBox select first "Debug" and in the treeview select "Configuration Properties" -->"Build" under "Ouputs" in the listview Change the ouput path to say "binaries\Debug"
repeat it with the "Release" change it to "binaries\Release"
Now you do have
1) Source Code Folder
2) binaries Folder
as for the obj folder leave it as it is
Ahmad Shaban
|
|
|
|
|
Ok,
Thank you, so these is no solution to move 'obj' directory
I'll be careful when I save my source code files to not add obj directory in SVN.
|
|
|
|
|
Hi
Actually i'm not sure !!
Ahmad Shaban
|
|
|
|
|
fregolo52 wrote: I'll be careful when I save my source code files to not add obj directory in SVN.
If your concern is including temp files in subversion, when first importing the source code. What I do normally is clean up the tree first import then go back on my way coding.
If you’re commiting code into the repository it should only mark the files for updating that already exist in the repository. If you want to add new files just parse through the list manually and make the check mark next to the file.
When pushing code back to the repository you can also right click on files, and chose to exclude them based on file extension.
Hope that helps.
-- modified at 5:51 Wednesday 22nd March, 2006
|
|
|
|
|
|
No problem, I trust thats what you where looking for?
|
|
|
|
|
Hi,
Is it possible to extract subarrays from multidimensional arrays in C#?
I.e., without traversing the whole thing with a for loop. Let's say I have a 2 x 100 matrix array and want to extract only one column in an array of its own.
I thought it would look like for instance:
int [,] twoDimArray = new int[2,100];
//
//...fill it with data here...
//
int[] oneDimArray = twoDimArray[1]
but it doesn't work.
Thanks.
|
|
|
|
|
No, that's because an array in .NET is not just the values in the array, but an object that manages the values, so a part of an array can't be used as an array.
An alternative to a two dimensional array is a jagged array, e.g. an array of arrays. It's a bit more work to create the array, as each column of the array also has to be created, but you can get a separate column from it exactly as you wanted.
---
b { font-weight: normal; }
|
|
|
|
|
Please provid the code for WSS Object Model
|
|
|
|
|
U can have a look at this relates to sharepoint object model
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Web;
using System.Xml;
using System.Data.SqlClient;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Administration;
using System.Web.UI.WebControls;
using Microsoft.ApplicationBlocks.Data;
namespace MyApp
{
///
/// Summary description for FCDocService.
///
public class FCDocService
{
private SPSite site = null;
private SPWeb web = null;
int iStatus;
private string portalURL = ConfigurationSettings.AppSettings["PORTALURL"];
private string assemblyInfo = ConfigurationSettings.AppSettings["ASSEMBLYINFO"];
private string assemblyClass = ConfigurationSettings.AppSettings["ASSEMBLYCLASS"];
private string assemblyDesc = ConfigurationSettings.AppSettings["ASSEMBLYDESC"];
public string currentSiteURL;
//For WorkFlow
SqlConnection objCon;
DataSet objDs;
SqlCommand objCmd;
SqlDataAdapter objDa;
public FCDocService()
{
site = new SPSite(portalURL);
web = site.AllWebs[0];
//objCon=new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
}
//
// public FCDocService(string strSite)
// {
// site = new SPSite(portalURL+ strSite);
// web = site.AllWebs[0];
//
// /*site = new SPSite(portalURL);
// web = site.AllWebs["sites/" + strSite]; */
// currentSiteURL=portalURL+strSite+"/";
//
// //SPSite site = new SPSite(portalURL+ strSite);
// //SPWeb spWeb = site.AllWebs[0];
//
// }
public FCDocService(string strSite)
{
//Added by Kishore
site = new SPSite(portalURL);
web = site.AllWebs["sites/" + strSite];
currentSiteURL=portalURL+strSite + "/";
}
public FCDocService(string strSite,string localPortal)
{
// site = new SPSite(portalURL+ strSite);
// web = site.AllWebs[0];
site = new SPSite(localPortal);
web = site.AllWebs["sites/" + strSite];
// currentSiteURL=portalURL+strSite+"/";
}
// public string SearchDocuments(string searchTerm)
// {
// string str="";
// SPSearchResultCollection resultCol=web.SearchDocuments(searchTerm);
//
// DataTable dt = new DataTable();
// DataRow dr;
// DataColumn dc = new DataColumn("Document");
// dt.Columns.Add(dc);
//
// for(int i=0;i<resultcol.count;i++)
{
="" str+="resultCol[i].Title" +="" ":"="" resultcol[i].listname.tostring()+="" resultcol[i].url="" "<br="">";
// }
// return str;
// }
///
/// This function is used to search documents in the share point portal server.
/// It accepts a string parameter named searchTerm.
///
/// <param name="searchTerm" />
/// <returns>
public DataSet SearchDocuments(string searchTerm)
{
string str="";
SPSearchResultCollection resultCol=web.SearchDocuments(searchTerm);
DataTable dt = new DataTable();
DataSet ds=new DataSet();
DataRow dr;
DataColumn dc;
dc= new DataColumn("Name");
dt.Columns.Add(dc);
dc= new DataColumn("Size");
dt.Columns.Add(dc);
dc= new DataColumn("Type");
dt.Columns.Add(dc);
dc= new DataColumn("DateModified");
dt.Columns.Add(dc);
dc= new DataColumn("URL");
dt.Columns.Add(dc);
for(int i=0;i<resultcol.count;i++)
{=""
="" if(string.compare(resultcol[i].title,"template.doc",true)!="0)
" {
="" dr="dt.NewRow();
" dr["name"]="resultCol[i].Title;
" dr["size"]="resultCol[i].Size/1024" +="" "="" kb";
="" dr["type"]="GetFileType(resultCol[i].Title);
" dr["datemodified"]="resultCol[i].DateLastModified;
" dr["url"]="web.Url+" +resultcol[i].listname+="" resultcol[i].title;="" dt.rows.add(dr);
="" }
="" ds.tables.add(dt);
="" return="" ds;
="" <summary="">
/// This function returns all the document libraries and permissions existing for a particular user.
///
/// <param name="strUser" />
/// <returns>
public DataTable GetDocLibraries(string strUser)
{
string strFolderName = "";
SPFolderCollection folderCol;
folderCol = web.Folders;
// HttpContext.Current.Response.Write("Url:"+web.Url);
// HttpContext.Current.Response.End();
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("DocumentLibrary");
dt.Columns.Add(dc);
DataColumn dcView = new DataColumn("View");
dt.Columns.Add(dcView);
DataColumn dcEdit = new DataColumn("Edit");
dt.Columns.Add(dcEdit);
DataColumn dcDelete = new DataColumn("Delete");
dt.Columns.Add(dcDelete);
DataColumn dcAdd = new DataColumn("Add");
dt.Columns.Add(dcAdd);
DataColumn [] pKeys=new DataColumn[1];
pKeys[0]=dt.Columns["DocumentLibrary"];
dt.PrimaryKey=pKeys;
ArrayList folderNames = new ArrayList();
foreach(SPFolder folder in folderCol)
{
dr = dt.NewRow();
strFolderName = folder.Name.Trim().ToString();
if(strFolderName.Substring(0,1) != "_" && strFolderName != "" && strFolderName.ToLower()!="lists" && strFolderName.ToLower()!="images")
{
dr["DocumentLibrary"] = folder.Name.ToString();
SPPermissionCollection sPPermissionCollection = web.Lists[folder.Name.ToString()].Permissions;
foreach(SPPermission spPermission in sPPermissionCollection)
{
if(spPermission.Member.ToString() == strUser)
{
string strPermissions = spPermission.PermissionMask.ToString();
if(strPermissions.IndexOf("ViewListItems") != -1)
{
dr["View"] = "true";
}
else
{
dr["View"] = "false";
}
if(strPermissions.IndexOf("EditListItems") != -1)
{
dr["Edit"] = "true";
}
else
{
dr["Edit"] = "false";
}
if(strPermissions.IndexOf("DeleteListItems") != -1)
{
dr["Delete"] = "true";
}
else
{
dr["Delete"] = "false";
}
if(strPermissions.IndexOf("AddListItems") != -1)
{
dr["Add"] = "true";
}
else
{
dr["Add"] = "false";
}
}
}
dt.Rows.Add(dr);
}
}
return dt;
}
///
/// This function returns all the document libraries as a DataTable
///
/// <returns>
public DataTable BindDocLibrary()
{
SPFolderCollection folderCol;
folderCol = web.Folders;
SPFolderCollection folderCol1;
DataSet dsDocumentLibraries = new DataSet();
DataTable dtFolders = new DataTable("dtFolders");
DataRow drFolders;
DataColumn dcFolderName = new DataColumn("FolderName");
dtFolders.Columns.Add(dcFolderName);
DataTable dtSubFolders = new DataTable("dtSubFolders");
DataRow drSubFolders;
DataColumn dcSubFolderName = new DataColumn("SubFolderName");
dtSubFolders.Columns.Add(dcSubFolderName);
DataColumn dcParentFolderName = new DataColumn("ParentFolderName");
dtSubFolders.Columns.Add(dcParentFolderName);
foreach(SPFolder folder in folderCol)
{
folderCol1=folder.SubFolders;
string strFolderName = folder.Name.ToUpper();
if(strFolderName != "IMAGES" && strFolderName != "_PRIVATE" && strFolderName != "SHARED DOCUMENTS" && strFolderName != "_CATALOGS" && strFolderName != "LISTS" )
{
drFolders = dtFolders.NewRow();
drFolders["FolderName"] = folder.Name.ToString();
dtFolders.Rows.Add(drFolders);
foreach(SPFolder folder1 in folderCol1)
{
string strSubFolderName = folder1.Name.ToUpper().ToString();
string v = folder1.ParentFolder.Name;
if(strSubFolderName != "FORMS" )
{
drSubFolders = dtSubFolders.NewRow();
drSubFolders["SubFolderName"] = folder1.Name;
drSubFolders["ParentFolderName"] = folder1.ParentFolder.Name;
dtSubFolders.Rows.Add(drSubFolders);
}
}
}
}
dsDocumentLibraries.Tables.Add(dtFolders);
dsDocumentLibraries.Tables.Add(dtSubFolders);
dsDocumentLibraries.Relations.Add("DocFol", dsDocumentLibraries.Tables["dtFolders"].Columns["FolderName"], dsDocumentLibraries.Tables["dtSubFolders"].Columns["ParentFolderName"]);
return dsDocumentLibraries.Tables["dtFolders"];
}
///
/// Adds document library to Share Point Site
///
/// <param name="docLibName" />New Document Library Name
/// <returns>True if created,Otherwise False
public bool AddDocumentLibrary(string docLibName,string strDescription,int iTemplateIndex)
{
SPList spList;
System.Guid guid;
web.AllowUnsafeUpdates = true;
try
{
guid=web.Lists.Add(docLibName, strDescription, web.ListTemplates["Document Library"], web.DocTemplates[iTemplateIndex]);
web.Lists[guid].EnableVersioning = true;
spList=web.Lists[guid];
spList.EnableVersioning = true;
spList.OnQuickLaunch=true;
spList.EnableModeration=true;
spList.Update();
spList.Fields.Add("CustomStatus",SPFieldType.Text,false);
spList.Fields.Add("ForUser",SPFieldType.Text,false);
spList.Fields.Add("Source",SPFieldType.Text,false);
spList.Fields.Add("FileCheckedOutBy",SPFieldType.Text,false);
spList.Fields.Add("FileModifiedBy",SPFieldType.Text,false);
web.Update();
if(guid.ToString().Length>0)
{
return true;
}
else
return false;
}
catch(Exception e)
{
return false;
}
}
public void DisplayProperties(string docLibName)
{
web.AllowUnsafeUpdates = true;
//SPListItemCollection items=(SPListItemCollection)web.Lists["SIGA_Documents"].Items;
//foreach(int i=0;i<items.count;i++)
{
="" httpcontext.current.response.write(items[i].fields[);
="" }
="" <summary="">
/// Adds a folder to the specified URL
///
/// <param name="strUrl" />
/// <returns>
public bool AddFolder(string strUrl)
{
web.AllowUnsafeUpdates=true;
SPFolder folder=web.GetFolder(strUrl);
if(!folder.Exists)
{
web.Folders.Add(strUrl);
//web.Update();
return true;
}
else
return false;
}
///
/// Delete document library From Share Point Site
///
/// <param name="docLibName" />Document Library Name
/// <returns>Returns True After Deletion
public bool DeleteDocumentLibrary(string docLibName)
{
System.Guid guid;
web.AllowUnsafeUpdates = true;
guid = web.Lists[docLibName].ID;
web.Lists.Delete(guid);
web.Update();
return true;
}
///
/// Upload Document to Document Library
///
/// <returns>Returns True after Uploading Document Library
public bool Upload(string fileName,string destiUrl,Stream fStream,string UserName)
{
string destUrl = destiUrl+fileName ;
SPWeb web = new SPSite(destUrl).OpenWeb();
web.AllowUnsafeUpdates = true;
SPUser userName=web.AllUsers[@UserName];
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
// HttpContext.Current.Response.Write(DateTime.Now);
// HttpContext.Current.Response.End();
web.Files.Add(destUrl, contents,userName,userName,DateTime.Now,DateTime.Now);
web.Update();
return true;
}
///
/// Uploads a documnet to the specified destination URL with the Parameters specified
///
/// <param name="fileName" />
/// <param name="destiUrl" />
/// <param name="fStream" />
/// <param name="UserName" />
/// <param name="primaryId" />
/// <param name="forUser" />
/// <param name="source" />
/// <returns>
public bool Upload(string fileName,string destiUrl,Stream fStream,string UserName,string primaryId,string forUser,string source)
{
string destUrl = destiUrl+fileName ;
// HttpContext.Current.Response.Write(destUrl);
// HttpContext.Current.Response.End();
SPWeb web = new SPSite(destUrl).OpenWeb();
web.AllowUnsafeUpdates = true;
SPUser userName=web.AllUsers[@UserName];
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
// HttpContext.Current.Response.Write(destUrl);
// HttpContext.Current.Response.End();
web.Files.Add(destUrl, contents,userName,userName,DateTime.Now,DateTime.Now);
web.Update();
SPFile file=web.GetFile(destUrl);
file.Item["CustomStatus"]=primaryId;
file.Item["ForUser"]=forUser;
file.Item["Source"]=source;
file.Item.Update();
// for(int i=0;i<file.item.fields.count;i++)
{
="" httpcontext.current.response.write(file.item.fields[i].title+="" ":"="" +="" file.item[i].tostring()="" +"<br="">");
// }
// HttpContext.Current.Response.End();
web.Update();
return true;
}
///
/// Checks whether the file exists in a specified document library or not and return true if the file exists
///
/// <param name="strDocLib" />
/// <param name="strFileName" />
/// <returns>
public bool FileExists(string strDocLib,string strFileName)
{
string url= currentSiteURL + strDocLib+"/"+strFileName;
SPFile file=web.GetFile(url);
if(file.Exists)
return true;
else
return false;
}
///
/// Returns the status of the file such by whom the file checked out.
///
/// <param name="strDocLib" />
/// <param name="strFileName" />
/// <returns>
public string CheckStatus(string strDocLib,string strFileName)
{
string url= currentSiteURL + strDocLib+"/"+strFileName;
SPFile fileCheck=web.GetFile(url);
return fileCheck.CheckOutStatus.ToString();
}
///
/// Lists all the users for a particulat document library.
///
/// <param name="strDocLibrary" />
/// <returns>
public DataTable AllUsers(string strDocLibrary)
{
DataTable dtAllUsers = new DataTable();
DataRow drAllUsers;
DataColumn dcUser = new DataColumn("User");
dtAllUsers.Columns.Add(dcUser);
web.AllowUnsafeUpdates = true;
SPPermissionCollection spPermissionCollection = web.Lists[strDocLibrary].Permissions;
SPUserCollection spUserCollection = web.Users;
foreach(SPUser spUser in spUserCollection)
{
drAllUsers = dtAllUsers.NewRow();
drAllUsers["User"] = spUser.LoginName;
dtAllUsers.Rows.Add(drAllUsers);
}
return dtAllUsers;
}
///
/// Not Used
///
/// <param name="strDocLibrary" />
/// <returns>
public DataTable AvailableUsers(string strDocLibrary)
{
DataTable dtAvailableUsers = new DataTable();
DataRow drAvailableUsers;
DataColumn dcUser = new DataColumn("User");
dtAvailableUsers.Columns.Add(dcUser);
DataColumn dcPermissions = new DataColumn("Permissions");
dtAvailableUsers.Columns.Add(dcPermissions);
web.AllowUnsafeUpdates = true;
SPPermissionCollection spPermissionCollection = web.Lists["FCDemo"].Permissions;
foreach(SPPermission spPermission in spPermissionCollection)
{
//arrUsers.Add(spPermission.Member + " " + spPermission.PermissionMask);
drAvailableUsers = dtAvailableUsers.NewRow();
drAvailableUsers["User"] = spPermission.Member;
drAvailableUsers["Permissions"] = spPermission.PermissionMask;
dtAvailableUsers.Rows.Add(drAvailableUsers);
}
return dtAvailableUsers;
}
///
/// Returns all the roles
///
/// <returns>
public DataTable AllRoles()
{
SPRoleCollection spRoleCollection = web.Roles;
DataTable dtAllRoles = new DataTable();
DataRow drAllRoles;
DataColumn dcRole = new DataColumn("Role");
dtAllRoles.Columns.Add(dcRole);
foreach(SPRole spRole in spRoleCollection)
{
drAllRoles = dtAllRoles.NewRow();
drAllRoles["Role"] = spRole.Name;
dtAllRoles.Rows.Add(drAllRoles);
}
return dtAllRoles;
}
///
/// Adds a user to the document library so that user can access the document library
///
/// <param name="strDocLibrary" />
/// <param name="strUser" />
/// <param name="blnViewItems" />
/// <param name="blnEditItems" />
/// <param name="blnDeleteItems" />
/// <param name="blnAddItems" />
/// <returns>
public bool AddUserDocumentLibrary(string strDocLibrary, string strUser, bool blnViewItems, bool blnEditItems, bool blnDeleteItems, bool blnAddItems)
{
web.AllowUnsafeUpdates = true;
SPPermissionCollection sPPermissionCollection = web.Lists[strDocLibrary].Permissions;
SPMember spMember = web.Users[strUser];
/*if(strPermission == "READER")
web.Lists[strDocLibrary].Permissions.Add(spMember,SPRights.ViewListItems | SPRights.AddListItems);
else if(strPermission == "ADMINISTRATOR")
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.d.e.FullMask);
*/
if(blnViewItems == true && blnEditItems == true && blnDeleteItems == true && blnAddItems == true)
{
web.Lists[strDocLibrary].Permissions.Add(spMember,SPRights.ViewListItems | SPRights.AddListItems | SPRights.DeleteListItems | SPRights.EditListItems);
}
if(blnViewItems == true && blnEditItems == false && blnDeleteItems == true && blnAddItems == true )
{
web.Lists[strDocLibrary].Permissions.Add(spMember,SPRights.ViewListItems | SPRights.AddListItems | SPRights.DeleteListItems);
}
if(blnViewItems == true && blnEditItems == true && blnDeleteItems == false && blnAddItems == true)
{
web.Lists[strDocLibrary].Permissions.Add(spMember,SPRights.ViewListItems | SPRights.AddListItems | SPRights.EditListItems);
}
if(blnViewItems == true && blnEditItems == false && blnDeleteItems == false && blnAddItems == true)
{
web.Lists[strDocLibrary].Permissions.Add(spMember,SPRights.ViewListItems | SPRights.AddListItems );
}
if(blnViewItems == true && blnEditItems == false && blnDeleteItems == false && blnAddItems == false )
{
web.Lists[strDocLibrary].Permissions.Add(spMember,SPRights.ViewListItems);
}
if(blnViewItems == false && blnEditItems == true && blnDeleteItems == true && blnAddItems == true )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.AddListItems | SPRights.DeleteListItems | SPRights.EditListItems);
}
if(blnViewItems == false && blnEditItems == true && blnDeleteItems == true && blnAddItems == false )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.DeleteListItems | SPRights.EditListItems);
}
if(blnViewItems == false && blnEditItems == false && blnDeleteItems == true && blnAddItems == false )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.DeleteListItems );
}
if(blnViewItems == false && blnEditItems == false && blnDeleteItems == false && blnAddItems == true )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.AddListItems);
}
if(blnViewItems == true && blnEditItems == true && blnDeleteItems == false && blnAddItems == false )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.ViewListItems | SPRights.EditListItems);
}
if(blnViewItems == false && blnEditItems == false && blnDeleteItems == true && blnAddItems == true )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.AddListItems | SPRights.DeleteListItems);
}
if(blnViewItems == false && blnEditItems == false && blnDeleteItems == false && blnAddItems == false )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.EmptyMask);
}
//Missed Combinations
if(blnViewItems == true && blnEditItems == true && blnDeleteItems == true && blnAddItems == false )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.ViewListItems | SPRights.EditListItems | SPRights.DeleteListItems);
}
if(blnViewItems == false && blnEditItems == true && blnDeleteItems == false && blnAddItems == true )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.AddListItems | SPRights.EditListItems);
}
if(blnViewItems == true && blnEditItems == false && blnDeleteItems == true && blnAddItems == false )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.ViewListItems | SPRights.DeleteListItems);
}
if(blnViewItems == false && blnEditItems == true && blnDeleteItems == false && blnAddItems == false )
{
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.EditListItems);
}
return true;
}
///
/// Deletes a user from the document library.
///
/// <param name="strDocLibrary" />
/// <param name="strUser" />
/// <returns>
public bool DeleteUserDocumentLibrary(string strDocLibrary, string strUser)
{
web.AllowUnsafeUpdates = true;
SPPermissionCollection sPPermissionCollection = web.Lists[strDocLibrary].Permissions;
SPMember spMember = web.Users[strUser];
web.Lists[strDocLibrary].Permissions.Remove(spMember);
return true;
}
///
/// Adds a specified role & permissions to a document library
///
/// <param name="strDocLibrary" />
/// <param name="strPermission" />
/// <param name="strRole" />
/// <returns>
public bool AddRoleDocumentLibrary(string strDocLibrary, string strPermission, string strRole)
{
web.AllowUnsafeUpdates = true;
SPPermissionCollection sPPermissionCollection = web.Lists[strDocLibrary].Permissions;
SPMember spMember = web.Roles[strRole];
if(strPermission == "READER")
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.ViewListItems);
else if(strPermission == "ADMINISTRATOR")
web.Lists[strDocLibrary].Permissions.Add(spMember, SPRights.FullMask);
return true;
}
///
/// Deletes a role from a document library
///
/// <param name="strDocLibrary" />
/// <param name="strRole" />
/// <returns>
public bool DeleteRoleDocumentLibrary(string strDocLibrary, string strRole)
{
web.AllowUnsafeUpdates = true;
SPPermissionCollection sPPermissionCollection = web.Lists[strDocLibrary].Permissions;
SPMember spMember = web.Roles[strRole];
web.Lists[strDocLibrary].Permissions.Remove(spMember);
return true;
}
///
/// Not in Use
///
/// <param name="strListDocLibray" />
/// <returns>
public DataTable DisplayFiles2(string strListDocLibray)
{
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
SPQuery allItemsQuery = new SPQuery();
allItemsQuery.ViewAttributes = "ModerationType='Moderator'";
SPListItemCollection listCol = docLib.GetItems(allItemsQuery);
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Document");
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("Status");
dt.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("CheckInStatus");
dt.Columns.Add(dc2);
foreach(SPListItem item in listCol)
{
if(item.ModerationInformation.Status.ToString()=="Approved")
{
dr = dt.NewRow();
dr["Document"] = item.File.Name;
dr["Status"] = item.ModerationInformation.Status.ToString();
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
string strCheckedOutBy = fileCheck.CheckedOutBy.LoginName;
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
}
}
return dt;
/*ArrayList arrListFies = new ArrayList();
foreach(SPListItem item in listCol)
{
arrListFies.Add(item.File.Name);
}
return arrListFies;
*/
}
///
/// Not in Use
///
/// <param name="strListDocLibray" />
/// <returns>
public DataTable DisplayFiles(string strListDocLibray)
{
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
SPQuery allItemsQuery = new SPQuery();
allItemsQuery.ViewAttributes = "ModerationType='Moderator'";
SPListItemCollection listCol = docLib.GetItems(allItemsQuery);
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Document");
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("Status");
dt.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("CheckInStatus");
dt.Columns.Add(dc2);
foreach(SPListItem item in listCol)
{
dr = dt.NewRow();
dr["Document"] = item.File.Name;
dr["Status"] = item.ModerationInformation.Status.ToString();
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
string strCheckedOutBy = fileCheck.CheckedOutBy.LoginName;
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
}
return dt;
/*ArrayList arrListFies = new ArrayList();
foreach(SPListItem item in listCol)
{
arrListFies.Add(item.File.Name);
}
return arrListFies;
*/
}
//Used in WorlFlow Page
///
/// Returns the Files based on the query passed to it.
///
/// <param name="strListDocLibray" />
/// <param name="strQuery" />
/// <param name="primaryid" />
/// <param name="userName" />
/// <returns>
public DataTable GetDocumentFiles(string strListDocLibray,string strQuery,string primaryid,string userName)
{
DataTable dt = new DataTable();
try
{
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
SPQuery query = new SPQuery();
// string strQuery="<where><eq><fieldref name="CustomStatus"><value type="Text">SIGA_C9168A9F";
// strQuery=strQuery + "<where><eq><fieldref name="ForUser"><value type="Text">HOL_DEV\\balakishore.golla";
// strQuery=strQuery + "<where><eq><fieldref name="Source"><value type="Text">DemoOrganize";
query.Query= strQuery;
SPListItemCollection listCol = docLib.GetItems(query);
DataRow dr;
DataColumn dCol;
dCol= new DataColumn("Name");
dt.Columns.Add(dCol);
//CustomStatus - name in Share point
dCol= new DataColumn("PrimaryId");
dt.Columns.Add(dCol);
dCol= new DataColumn("ForUser");
dt.Columns.Add(dCol);
foreach(SPListItem item in listCol)
{
if(item["ForUser"].ToString().ToLower().Trim()==userName.ToLower().Trim() && item["CustomStatus"].ToString().ToString().ToLower()==primaryid.ToLower().Trim())
{
dr = dt.NewRow();
dr["Name"]=item["Name"].ToString();
dr["PrimaryId"]=item["CustomStatus"].ToString();
dr["ForUser"]=item["ForUser"];
dt.Rows.Add(dr);
}
}
}
catch (Exception e1){}
return dt;
}
///
/// Returns the Files based on the query passed to it.
///
/// <param name="strListDocLibray" />
/// <param name="strQuery" />
/// <param name="primaryid" />
/// <returns>
public DataTable GetDocumentFiles(string strListDocLibray,string strQuery,string primaryid)
{
DataTable dt = new DataTable();
try
{
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
SPQuery query = new SPQuery();
query.Query= strQuery;
SPListItemCollection listCol = docLib.GetItems(query);
DataRow dr;
DataColumn dCol;
dCol= new DataColumn("Name");
dt.Columns.Add(dCol);
//CustomStatus - name in Share point
dCol= new DataColumn("PrimaryId");
dt.Columns.Add(dCol);
dCol= new DataColumn("ForUser");
dt.Columns.Add(dCol);
foreach(SPListItem item in listCol)
{
if(item["CustomStatus"].ToString().ToString().ToLower()==primaryid.ToLower().Trim())
{
dr = dt.NewRow();
dr["Name"]=item["Name"].ToString();
dr["PrimaryId"]=item["CustomStatus"].ToString();
dr["ForUser"]=item["ForUser"];
dt.Rows.Add(dr);
}
}
}
catch (Exception e1){}
return dt;
}
///
/// Not in use
///
/// <param name="strListDocLibray" />
/// <returns>
public DataTable DisplayFiles1(string strListDocLibray)
{
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
SPQuery allItemsQuery = new SPQuery();
allItemsQuery.ViewAttributes = "ModerationType='Moderator'";
SPListItemCollection listCol = docLib.GetItems(allItemsQuery);
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Document");
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("Path");
dt.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("Owner");
dt.Columns.Add(dc2);
DataColumn dc3 = new DataColumn("Status");
dt.Columns.Add(dc3);
foreach(SPListItem item in listCol)
{
dr = dt.NewRow();
dr["Document"] = item.File.Name;
dr["Path"] =item.File.Url.ToString() ;
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
dr["Owner"] = item.File.ModifiedBy.ToString();
dr["Status"]=item.ModerationInformation.Status.ToString();
dt.Rows.Add(dr);
}
return dt;
/*ArrayList arrListFies = new ArrayList();
foreach(SPListItem item in listCol)
{
arrListFies.Add(item.File.Name);
}
return arrListFies;
*/
}
///
/// returns the files list as a DataTable depending on the boolean value passed to it.
///
/// <param name="strListDocLibray" />
/// <param name="approved" />
/// <param name="reject" />
/// <param name="pending" />
/// <returns>
public DataTable AllFiles(string strListDocLibray,bool approved,bool reject,bool pending)
{
//SPSite site = new SPSite(portalURL);
//SPWeb web = site.AllWebs[0];
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
SPQuery allItemsQuery = new SPQuery();
allItemsQuery.ViewAttributes = "ModerationType='Moderator'";
SPListItemCollection listCol = docLib.GetItems(allItemsQuery);
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Document");
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("Status");
dt.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("CheckInStatus");
dt.Columns.Add(dc2);
foreach(SPListItem item in listCol)
{
if((approved)&&(item.ModerationInformation.Status ==SPModerationStatusType.Approved))
{
dr = dt.NewRow();
dr["Document"] = item.File.Name;
string k = item.File.Name;
dr["Status"] = item.ModerationInformation.Status.ToString();
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
string strCheckedOutBy = fileCheck.CheckedOutBy.LoginName;
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
//dr["CheckInStatus"] = "";
dt.Rows.Add(dr);
//arrListFies.Add(item.File.Name);
}
if((reject)&&(item.ModerationInformation.Status==SPModerationStatusType.Denied))
{
//arrListFies.Add(item.File.Name);
dr = dt.NewRow();
dr["Document"] = item.File.Name;
string k = item.File.Name;
dr["Status"] = item.ModerationInformation.Status.ToString();
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
string strCheckedOutBy = fileCheck.CheckedOutBy.LoginName;
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
}
if((pending)&&(item.ModerationInformation.Status==SPModerationStatusType.Pending))
{
//arrListFies.Add(item.File.Name);
dr = dt.NewRow();
dr["Document"] = item.File.Name;
string k = item.File.Name;
dr["Status"] = item.ModerationInformation.Status.ToString();
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
string strCheckedOutBy = fileCheck.CheckedOutBy.LoginName;
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
//dr["CheckInStatus"] = "";
dt.Rows.Add(dr);
}
}
return dt;
}
///
/// Not in Use
///
/// <param name="strListDocLibray" />
/// <param name="approved" />
/// <param name="reject" />
/// <param name="pending" />
/// <returns>
public DataTable AllFiles1(string strListDocLibray,bool approved,bool reject,bool pending)
{
//SPSite site = new SPSite(portalURL);
//web = site.AllWebs[0];
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
SPQuery allItemsQuery = new SPQuery();
allItemsQuery.ViewAttributes = "ModerationType='Moderator'";
SPListItemCollection listCol = docLib.GetItems(allItemsQuery);
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Document");
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("Path");
dt.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("Owner");
dt.Columns.Add(dc2);
DataColumn dc3 = new DataColumn("Status");
dt.Columns.Add(dc3);
DataColumn dc4 = new DataColumn("CheckInStatus");
dt.Columns.Add(dc4);
DataColumn [] pKey=new DataColumn[1];
pKey[0]=dt.Columns[0];
dt.PrimaryKey=pKey;
foreach(SPListItem item in listCol)
{
if((approved)&&(item.ModerationInformation.Status ==SPModerationStatusType.Approved))
{
dr = dt.NewRow();
dr["Document"] = item.File.Name;
dr["Path"]=item.File.Url.ToString();
dr["Owner"]=item.File.ModifiedBy.ToString();
dr["Status"]=item.ModerationInformation.Status.ToString();;
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
string strCheckedOutBy = fileCheck.CheckedOutBy.LoginName;
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
}
if((reject)&&(item.ModerationInformation.Status==SPModerationStatusType.Denied))
{
dr = dt.NewRow();
dr["Document"] = item.File.Name;
dr["Path"]=item.File.Url.ToString();
dr["Owner"]=item.File.ModifiedBy.ToString();
dr["Status"]=item.ModerationInformation.Status.ToString();;
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
string strCheckedOutBy = fileCheck.CheckedOutBy.LoginName;
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
}
if((pending)&&(item.ModerationInformation.Status==SPModerationStatusType.Pending))
{
//arrListFies.Add(item.File.Name);
dr = dt.NewRow();
dr["Document"] = item.File.Name;
dr["Path"]=item.File.Url.ToString();
dr["Owner"]=item.File.ModifiedBy.ToString();
dr["Status"]=item.ModerationInformation.Status.ToString();
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
string strCheckedOutBy = fileCheck.CheckedOutBy.LoginName;
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
}
}
return dt;
}
///
/// Returns the File Type given the filename
///
/// <param name="sFile" />
/// <returns>
private string GetFileType(string sFile)
{
int iIndex;
string strExt="",strDocDesc;
iIndex=sFile.ToString().LastIndexOf(".");
if(iIndex>0)
strExt=sFile.ToString().Substring(iIndex+1,3);
if(String.Compare(strExt,"doc",true)==0)
strDocDesc="Microsoft Word Document";
else if (String.Compare(strExt,"xls",true)==0)
strDocDesc="Microsoft Excel Worksheet";
else if(String.Compare(strExt,"ppt",true)==0)
strDocDesc="Microsoft PowerPoint Presentation";
else if(String.Compare(strExt,"pdf",true)==0)
strDocDesc="Adobe Acrobat Document";
else if(String.Compare(strExt,"txt",true)==0)
strDocDesc="Text Document";
else if(String.Compare(strExt,"zip",true)==0)
strDocDesc="WinZip File";
else if(String.Compare(strExt,"gif",true)==0)
strDocDesc="GIF Image";
else if(String.Compare(strExt,"jpg",true)==0 || String.Compare(strExt,"jpeg",true)==0)
strDocDesc="JPEG Image";
else
strDocDesc="";
return strDocDesc;
}
public string GetFileCheckedOut(string strDocLib,string strFileName)
{
string url= currentSiteURL + strDocLib+"/"+strFileName;
string strCheckedOutBy;
SPFile file=web.GetFile(url);
if(file.Item["FileCheckedOutBy"]!=null)
return file.Item["FileCheckedOutBy"].ToString();
else
return "";
}
///
/// Returns all the Files depending on the status passed to it.
///
/// <param name="url" />
/// <param name="status" />
/// <returns>
public DataTable GetFiles(string url,int status)
{
//SPSite site = new SPSite(portalURL);
//web = site.AllWebs[0];
string strExt="";
int iIndex;
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Document");
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("Path");
dt.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("Owner");
dt.Columns.Add(dc2);
DataColumn dc3 = new DataColumn("Status");
dt.Columns.Add(dc3);
DataColumn dc4 = new DataColumn("CheckInStatus");
dt.Columns.Add(dc4);
DataColumn dc5 = new DataColumn("Size");
dt.Columns.Add(dc5);
DataColumn dc6 = new DataColumn("FileType");
dt.Columns.Add(dc6);
DataColumn dc7 = new DataColumn("ModifiedDate");
dt.Columns.Add(dc7);
DataColumn [] pKey=new DataColumn[1];
pKey[0]=dt.Columns[0];
dt.PrimaryKey=pKey;
SPFileCollection fileCol;
SPFolder folder;
folder=web.GetFolder(url);
fileCol=folder.Files;
foreach(SPFile file in fileCol)
{
if(status==0)
{
dr = dt.NewRow();
dr["Document"] = file.Name;
dr["Path"]=file.Url.ToString();
dr["Owner"]=file.ModifiedBy.ToString();
dr["Status"]=file.Item.ModerationInformation.Status.ToString();
dr["Size"]=(file.TotalLength / 1024.0) + " KB";
dr["FileType"]=this.GetFileType(file.ToString());
dr["ModifiedDate"]=file.TimeLastModified.ToString();
string strStatus = file.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
//string strCheckedOutBy = file.CheckedOutBy.LoginName;
string strCheckedOutBy=file.Item["CheckedOutTo"].ToString();
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
}
else
{
if((file.Item.ModerationInformation.Status ==SPModerationStatusType.Approved) && status==1)
{
dr = dt.NewRow();
dr["Document"] = file.Name;
dr["Path"]=file.Url.ToString();
dr["Size"]=(int)file.TotalLength / 1024 + " KB";
dr["FileType"]=this.GetFileType(file.ToString());
dr["ModifiedDate"]=file.TimeLastModified.ToString();
//dr["Owner"]=file.ModifiedBy.ToString();
if(file.Item["FileModifiedBy"]!=null)
if(file.Item["FileModifiedBy"].ToString().Trim()!="")
dr["Owner"]=file.Item["FileModifiedBy"].ToString();
else
{
SPUser user=file.Author;
dr["Owner"]=user.LoginName;
}
else
{
SPUser user=file.Author;
dr["Owner"]=user.LoginName;
}
dr["Status"]=file.Item.ModerationInformation.Status.ToString();
string strStatus = file.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
//string strCheckedOutBy = file.CheckedOutBy.LoginName;
string strCheckedOutBy=file.Item["FileCheckedOutBy"].ToString();
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
}
if((file.Item.ModerationInformation.Status ==SPModerationStatusType.Denied) && status==2)
{
dr = dt.NewRow();
dr["Document"] = file.Name;
dr["Path"]=file.Url.ToString();
dr["Size"]=(int)(file.TotalLength / 1024) + " KB";
dr["FileType"]=this.GetFileType(file.ToString());
dr["ModifiedDate"]=file.TimeLastModified.ToString();
//dr["Owner"]=file.ModifiedBy.ToString();
if(file.Item["FileModifiedBy"]!=null)
if(file.Item["FileModifiedBy"].ToString().Trim()!="")
dr["Owner"]=file.Item["FileModifiedBy"].ToString();
else
{
SPUser user=file.Author;
dr["Owner"]=user.LoginName;
}
else
{
SPUser user=file.Author;
dr["Owner"]=user.LoginName;
}
dr["Status"]=file.Item.ModerationInformation.Status.ToString();
string strStatus = file.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
//string strCheckedOutBy = file.CheckedOutBy.LoginName;
string strCheckedOutBy=file.Item["FileCheckedOutBy"].ToString();
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
// dr["Document"] = file.Name;
// dr["Path"]=file.Url.ToString();
// dr["Owner"]=file.ModifiedBy.ToString();
// dr["Status"]=file.Item.ModerationInformation.Status.ToString();
//
// string strStatus = file.CheckOutStatus.ToString();
//
// if(strStatus.ToString().ToUpper() == "NONE")
// {
// dr["CheckInStatus"] = "";
// }
// else
// {
// string strCheckedOutBy = file.CheckedOutBy.LoginName;
// //string strCheckedOutBy=file.Item["CheckedOutTo"].ToString();
// dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
// }
}
if((file.Item.ModerationInformation.Status ==SPModerationStatusType.Pending) && status==3)
{
dr = dt.NewRow();
dr["Document"] = file.Name;
dr["Path"]=file.Url.ToString();
dr["Size"]=(int)(file.TotalLength / 1024) + " KB";
dr["FileType"]=this.GetFileType(file.ToString());
dr["ModifiedDate"]=file.TimeLastModified.ToString();
//dr["Owner"]=file.ModifiedBy.ToString();
if(file.Item["FileModifiedBy"]!=null)
if(file.Item["FileModifiedBy"].ToString().Trim()!="")
dr["Owner"]=file.Item["FileModifiedBy"].ToString();
else
{
SPUser user=file.Author;
dr["Owner"]=user.LoginName;
}
else
{
SPUser user=file.Author;
dr["Owner"]=user.LoginName;
}
dr["Status"]=file.Item.ModerationInformation.Status.ToString();
string strStatus = file.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
//string strCheckedOutBy = file.CheckedOutBy.LoginName;
string strCheckedOutBy=file.Item["FileCheckedOutBy"].ToString();
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
// dr["Document"] = file.Name;
// dr["Path"]=file.Url.ToString();
// dr["Owner"]=file.ModifiedBy.ToString();
// dr["Status"]=file.Item.ModerationInformation.Status.ToString();
//
// string strStatus = file.CheckOutStatus.ToString();
//
// if(strStatus.ToString().ToUpper() == "NONE")
// {
// dr["CheckInStatus"] = "";
// }
// else
// {
// string strCheckedOutBy = file.CheckedOutBy.LoginName;
// //string strCheckedOutBy=file.Item["CheckedOutTo"].ToString();
// dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
// }
}
}
}
return dt;
}
///
/// Inserts the File Approvers data into the Database
///
/// <param name="strDocLibId" />
/// <param name="strFileName" />
/// <param name="strFileOwner" />
/// <param name="strRepAuth" />
/// <param name="status" />
/// <returns>
public int InserFileApprovers(string strDocLibId,string strFileName,string strFileOwner,string strRepAuth,string status)
{
try
{
objCon=new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
objCmd=new SqlCommand("USP_INSERT_FILEAPPROVERS",objCon);
objCmd.CommandType=CommandType.StoredProcedure;
if(objCon.State==ConnectionState.Closed)
objCon.Open();
SqlParameter objParam;
objParam=new SqlParameter("@DocLibId",SqlDbType.VarChar,255);
objParam.Value=strDocLibId.ToString();
objCmd.Parameters.Add(objParam);
objParam=new SqlParameter("@FileName ",SqlDbType.VarChar,255);
objParam.Value=strFileName;
objCmd.Parameters.Add(objParam);
objParam=new SqlParameter("@FileOwner ",SqlDbType.VarChar,255);
objParam.Value=strFileOwner;
objCmd.Parameters.Add(objParam);
objParam=new SqlParameter("@ReportingAuthority ",SqlDbType.VarChar,255);
objParam.Value=strRepAuth;
objCmd.Parameters.Add(objParam);
objParam=new SqlParameter("@Status ",SqlDbType.VarChar,25);
objParam.Value=status;
objCmd.Parameters.Add(objParam);
if(objCmd.ExecuteNonQuery()>0)
{
objCon.Close();
iStatus=1;
}
else
{
objCon.Close();
iStatus=-1;
}
}
catch(Exception e)
{
// HttpContext.Current.Response.Write(e.Message);
// HttpContext.Current.Response.End();
}
return iStatus;
}
///
/// Not in Use
///
/// <param name="strListDocLibray" />
/// <returns>
public ArrayList Alert(string strListDocLibray)
{
//SPSite site = new SPSite(portalURL);
//SPWeb web = site.AllWebs[0];
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
SPListItemCollection listCol = docLib.Items;
ArrayList arrListFies = new ArrayList();
foreach(SPListItem item in listCol)
{
arrListFies.Add(item.File.Name);
web.AllowUnsafeUpdates = true;
web.Alerts.Add(item,SPEventType.All,SPAlertFrequency.Immediate) ;
}
return arrListFies;
}
///
/// Not in use
///
/// <param name="strDocLibName" />
/// <param name="strFileName" />
/// <returns>
public bool DeleteFile(string strDocLibName,string strFileName)
{
//SPSite site=new SPSite(currentSiteURL);
//SPWeb web=site.AllWebs[0];
web.AllowUnsafeUpdates=true;
SPDocumentLibrary docLib=(SPDocumentLibrary)web.Lists[strDocLibName];
SPListItemCollection listCol=docLib.Items;
for(int i=0;i<listcol.count;i++)
="" {
="" if(strfilename="=listCol[i].File.Name)
" changefilestatus(strdoclibname,strfilename,"0");
="" listcol.delete(i);
="" }
="" web.update();
="" return="" true;
="" <summary=""> /// Deletes a specified file from the document library
///
/// <param name="strDocLibName" />
/// <param name="strFileName" />
/// <returns>
public bool DeleteFile1(string strDocLibName,string strFileName)
{
// SPSite site=new SPSite(currentSiteURL);
// SPWeb web=site.AllWebs[0];
// SPDocumentLibrary docLib=(SPDocumentLibrary)web.Lists[strDocLibName];
// SPListItemCollection listCol=docLib.Items;
web.AllowUnsafeUpdates=true;
string url=currentSiteURL+strDocLibName+"/"+strFileName;
string strFolderUrl=currentSiteURL+strDocLibName;
//HttpContext.Current.Response.Write(url+" ");
//HttpContext.Current.Response.Write(url1+" ");
//HttpContext.Current.Response.End();
string fileUrl="";
SPFile file=web.GetFile(url);
file.Item.ModerationInformation.Status=SPModerationStatusType.Approved;
file.Item.Update();
//web.Update();
SPFileCollection fileCol;
SPFolder folder;
folder=web.GetFolder(strFolderUrl);
fileCol=folder.Files;
for(int i=0;i<filecol.count;i++)
="" {
="" if(strfilename="=fileCol[i].Name.ToString())
" {="" fileurl="fileCol[i].Url;" filecol.delete(fileurl);
="" }
="" web.update();
="" return="" true;
="" <summary="">
/// Returns Filename From the Specified Path
///
/// <param name="strPath" />URL to extract the filename
/// <returns>Returns FileName
public string GetFileName(string strPath)
{
string [] fileName;
char [] sep = new char[] {'\\'};
string strFileName;
fileName = strPath.Split(sep);
strFileName = fileName[fileName.Length-1];
return strFileName;
}
///
/// Lists all the versions of a file as an ArrayList
///
/// <param name="strListDocLibrary" />
/// <param name="strListFileItem" />
/// <returns>
public ArrayList DisplayFileVersions(string strListDocLibrary,string strListFileItem)
{
string url=currentSiteURL + strListDocLibrary + "/" + strListFileItem;
SPFile file = web.GetFile(url);
SPFileVersionCollection fileVerCol = file.Versions;
ArrayList SPFileVer = new ArrayList();
string strMsg="",strCreatedBy="",strOp="";
if(fileVerCol.Count>0)
strCreatedBy=fileVerCol[0].CreatedBy.ToString()+ " - " + fileVerCol[0].Created.ToShortDateString() + " - " + file.CheckInComment;
for(int i=0;i<filevercol.count;i++)
{=""
="" strmsg="" ;
="" strop="" if(filevercol[i].checkincomment.tostring().length<="0)
" {
="" "="" -="" +="" filevercol[i].created.toshortdatestring();
="" }
="" else
="" filevercol[i].created.toshortdatestring()+="" filevercol[i].checkincomment.tostring();
="" if(i="=0)
" author="" ";
="" spfilever.add(strmsg);
="" if(filevercol.count="">0)
SPFileVer.Add(strCreatedBy);
return SPFileVer;
}
///
/// Lists all the versions of a file as a DataTable
///
/// <param name="strListDocLibrary" />
/// <param name="strListFileItem" />
/// <returns>
public DataView DisplayFileVersions1(string strListDocLibrary,string strListFileItem)
{
//To open the old document
string url=currentSiteURL + strListDocLibrary + "/" + strListFileItem;
SPFile file = web.GetFile(url);
SPFileVersionCollection fileVerCol = file.Versions;
//ArrayList SPFileVer = new ArrayList();
//string strMsg="",strCreatedBy="",strOp="";
DataTable dt = new DataTable();
DataRow dr;
// DataColumn dc = new DataColumn("Document");
// dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("CreatedBy");
dt.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("CreationDate");
dt.Columns.Add(dc2);
DataColumn dc3 = new DataColumn("CheckInComment");
dt.Columns.Add(dc3);
DataColumn dc4 = new DataColumn("Id",typeof(System.Int32));
dt.Columns.Add(dc4);
DataColumn dc5 = new DataColumn("url");
dt.Columns.Add(dc5);
DataColumn dc6 = new DataColumn("Size");
dt.Columns.Add(dc6);
DataColumn [] pKeys=new DataColumn[1];
pKeys[0]=dc4;
dt.PrimaryKey=pKeys;
string strTemp,str,strComment="";
int iTemp=0;
for(int i=0;i<filevercol.count;i++)
{
="" dr="dt.NewRow();
" dr["id"]="fileVerCol[i].ID;
" str="" ;
="" strtemp="" strcomment=""
="" if(strtemp.length="">0)
{
int iIndex=strTemp.IndexOf("%")+1;
int iLastIndex=strTemp.LastIndexOf("%");
if(strTemp.IndexOf("%")!=-1)
{
str=strTemp.Substring(iIndex,iLastIndex-iIndex);
strComment=strTemp.Substring(0,iIndex-1);
}
else
{
str="";
strComment=strTemp;
}
}
else
str="";
dr["CreationDate"]=fileVerCol[i].Created.ToLocalTime();
dr["CheckInComment"]=strComment;
if(i==0)
{
dr["CheckInComment"]+= "Author";
dr["CreatedBy"]=fileVerCol[i].CreatedBy.ToString();
}
else
{
dr["CreatedBy"]=str;
}
//dr["CreatedBy"]=fileVerCol[i].CreatedBy.ToString();
//dr["CheckInComment"]=fileVerCol[i].CheckInComment.ToString();
dr["url"]=fileVerCol[i].Url.ToString();
dr["Size"]=fileVerCol[i].Size / 1024.0 + " KB";
dt.Rows.Add(dr);
iTemp=i+1;
}
if(fileVerCol.Count>0)
{
dr = dt.NewRow();
dr["Id"]=iTemp + 1;
//dr["CreatedBy"]=fileVerCol[0].File.ModifiedBy.ToString();
str="";
strTemp=fileVerCol[0].File.CheckInComment.ToString();
if(strTemp.Length>0)
{
int iIndex=strTemp.IndexOf("%")+1;
int iLastIndex=strTemp.LastIndexOf("%");
if(strTemp.IndexOf("%")!=-1)
{
str=strTemp.Substring(iIndex,iLastIndex-iIndex);
strComment=strTemp.Substring(0,iIndex-1);
}
else
{
str="";
strComment=strTemp;
}
}
else
str="";
dr["CreatedBy"]=str;
dr["CreationDate"]=fileVerCol[0].File.TimeLastModified.ToLocalTime();
//dr["CheckInComment"]=fileVerCol[0].File.CheckInComment.ToString();
dr["CheckInComment"]=strComment;
dr["url"]=strListDocLibrary + "/" + strListFileItem;
dr["Size"]=fileVerCol[0].File.Length / 1024.0 + " KB";
dt.Rows.Add(dr);
}
DataView dv=new DataView(dt);
dv.Sort="id desc";
//HttpContext.Current.Response.End();
return dv;
}
///
/// Checks in the specified file and writes the commnets passed to it.
///
/// <param name="strListItem" />
/// <param name="strListFileItem" />
/// <param name="comments" />
/// <returns>
public string CheckIn(string strListItem,string strListFileItem,string comments)
{
// SPSite site = new SPSite(currentSiteURL+strListItem);
//
// SPWeb web = site.AllWebs[0];
web.AllowUnsafeUpdates = true;
string url = currentSiteURL+strListItem+"/"+strListFileItem;
SPFile fileIn = web.GetFile(url);
fileIn.CheckIn(comments);
web.Update();
return fileIn.CheckOutStatus.ToString();
}
///
/// Checks in the specified file and writes the commnets passed to it and updates the modifiedBy user defined column
///
/// <param name="strListItem" />
/// <param name="strListFileItem" />
/// <param name="comments" />
/// <param name="modifiedBy" />
/// <returns>
public string CheckIn(string strListItem,string strListFileItem,string comments,string modifiedBy)
{
web.AllowUnsafeUpdates = true;
string url = currentSiteURL+strListItem+"/"+strListFileItem;
SPFile fileIn = web.GetFile(url);
fileIn.CheckIn(comments+"%" + modifiedBy + "%");
fileIn.Item["FileCheckedOutBy"]="";
fileIn.Item["FileModifiedBy"]=modifiedBy;
fileIn.Item.Update();
SPFileVersionCollection fileVerCol=fileIn.Versions;
fileVerCol.Delete(fileIn.Versions.Count-1);
//web.Update();
return fileIn.CheckOutStatus.ToString();
}
///
/// Check out the specified file.
///
/// <param name="strListDocLibrary" />
/// <param name="strListFileItem" />
/// <returns>
public string CheckOut(string strListDocLibrary,string strListFileItem)
{
web.AllowUnsafeUpdates = true;
string url = currentSiteURL + strListDocLibrary+"/"+strListFileItem;
SPFile fileOut = web.GetFile(url);
fileOut.CheckOut();
web.Update();
return fileOut.CheckOutStatus.ToString();
}
///
/// Checks out the file and updates the user defined column checkedOutTo
///
/// <param name="strListDocLibrary" />
/// <param name="strListFileItem" />
/// <param name="checkedOutTo" />
/// <returns>
public string CheckOut(string strListDocLibrary,string strListFileItem,string checkedOutTo)
{
web.AllowUnsafeUpdates = true;
string url = currentSiteURL + strListDocLibrary+"/"+strListFileItem;
SPFile fileOut = web.GetFile(url);
//HttpContext.Current.Response.Write(url);
//HttpContext.Current.Response.End();
fileOut.Item["FileCheckedOutBy"]=checkedOutTo;
//fileOut.Versions[fileOut.Versions.Count-1].Properties.Add("FileCheckedOutBy",@"hol_dev\kirankumar.cholleti");
fileOut.Item.Update();
fileOut.CheckOut();
SPFileVersionCollection fileVerCol=fileOut.Versions;
fileVerCol.Delete(fileOut.Versions.Count-1);
//web.Update();
return fileOut.CheckOutStatus.ToString();
}
///
/// Not in Use
///
/// <returns>
public DataTable DisplaySites()
{
SPGlobalAdmin globAdmin = new SPGlobalAdmin();
System.Uri uri = new System.Uri(portalURL);
SPVirtualServer virtualServer =globAdmin.OpenVirtualServer(uri);// globAdmin.Opehttp;//dev206/MyAppWorkFlow/MyApp/newDoc.aspxnVirtualServer(uri);
SPSiteCollection siteCollections = virtualServer.Sites;
//ArrayList arrSites = new ArrayList();
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Site");
dt.Columns.Add(dc);
foreach(SPSite site in siteCollections)
{
string str;
if(site.Url.LastIndexOf("/sites/")!=-1)
{
str=site.Url.Substring(site.Url.LastIndexOf("/sites/")+1);
str=str.Substring(str.LastIndexOf("/")+1);
dr = dt.NewRow();
dr["Site"] = str;
dt.Rows.Add(dr);
}
}
return dt;
}
///
/// This function will create a site in Sharepoint portal server
///
/// <param name="strSiteName" />
/// <param name="strSiteTitle" />
/// <param name="strSiteDesc" />
/// <param name="strSiteTemplate" />
/// <param name="strOwnerLogin" />
/// <param name="strOwnerName" />
/// <param name="strOwnerEmail" />
public void CreateSite(string strSiteName,string strSiteTitle,string strSiteDesc,string strSiteTemplate,string strOwnerLogin,string strOwnerName,string strOwnerEmail)
{
SPGlobalAdmin globAdmin = new SPGlobalAdmin();
System.Uri uri = new System.Uri(portalURL);
SPVirtualServer virtualServer = globAdmin.OpenVirtualServer(uri);
SPSiteCollection siteCollections = virtualServer.Sites;
siteCollections.Add(portalURL + strSiteName ,strSiteTitle,strSiteDesc,1033,strSiteTemplate,strOwnerLogin,strOwnerName,strOwnerEmail);
globAdmin.Close();
}
///
/// This function will create a subsite in Sharepoint portal server
///
/// <param name="strSiteName" />
/// <param name="strSiteTitle" />
/// <param name="strDescription" />
/// <param name="strWebTemplate" />
public void CreateSubsite(string strSiteName, string strSiteTitle, string strDescription, string strWebTemplate)
{
// SPSite Site = new SPSite(currentSiteURL);
// SPWeb mySite = Site.AllWebs[0];
// SPWebCollection webs = web.Webs;
// SPWeb newweb= webs.Add(strSiteName, strSiteTitle, strDescription, 1033, strWebTemplate, false, false);
SPWebCollection subSites = web.Webs;
subSites.Add(strSiteName, strSiteTitle, strDescription, 1033, strWebTemplate,true,false);
}
///
/// This function deletes a Sharepoint Site
///
/// <param name="strSiteName" />
public void DeleteSite(string strSiteName)
{
SPSite mySite = new SPSite(portalURL + strSiteName);
mySite.Delete();
//// web.Delete();
// SPWebCollection subSites = web.Webs;
// subSites.Delete(strSiteName);
//mySite.Close();
}
///
/// This function deletes a subsite in Sharepoint Site
///
/// <param name="strSubSiteName" />
public void DeleteSubSite(string strSubSiteName)
{
SPWebCollection subSites = web.Webs;
subSites.Delete(strSubSiteName);
}
///
/// Not in Use
///
/// <param name="strDocLib" />
public void AddEventHandlerAssemblyData(string strDocLib)
{
// SPSite site;
// SPWeb web;
SPList spList;
System.Guid guid;
site=new SPSite(currentSiteURL);
web=site.AllWebs[0];
web.AllowUnsafeUpdates=true;
guid=web.Lists[strDocLib].ID;
spList=web.Lists[guid];
spList.EventSinkAssembly= assemblyInfo ;
spList.EventSinkClass=assemblyClass;
spList.EventSinkData=assemblyDesc;
spList.Update();
}
#region Old
/* public string CheckApproval(string strDocLibName,string strFileName,bool approvestate,bool rejstate,bool pendingstate)
{
//strFileName = DropDownList3.SelectedItem.Text
//strDocLibName =DropDownList1.SelectedItem.Text
SPSite site=new SPSite(portalURL);
SPWeb web= site.AllWebs[0];
web.AllowUnsafeUpdates=true;
string url=portalURL+strDocLibName+"/"+strFileName;
string message ="";
SPFile file=web.GetFile(url);
if(approvestate)
{
//file.Item.ModerationInformation.Status=SPModerationStatusType.Approved;
try
{
if(!file.Exists)
message="File doesn't exists";
else
{
file.MoveTo(portalURL+"Approve/"+strFileName);
message= "File Approved";
}
}
catch(Exception ee)
{
if( file.Exists==true)
message= ""+"File Already Exists"+"";
else
message =ee.ToString();
}
}
else if (rejstate)
{
//file.Item.ModerationInformation.Status=SPModerationStatusType.Denied;
try
{
if(!file.Exists)
message="File doesn't exists";
else
{
file.MoveTo(portalURL+"Reject/"+strFileName);
message= "File Rejected";
}
}
catch (Exception ee)
{
if(file.Exists)
message = "" +"File Already Exists"+"";
else
{
message =ee.ToString();
}
}
}
else
{
//file.Item.ModerationInformation.Status=SPModerationStatusType.Pending;
try
{
if(!file.Exists)
message="File doesn't exists";
else
{
file.MoveTo(portalURL+"Pending/"+strFileName);
message= "File In PendingList";
}
}
catch (Exception ee)
{
if(file.Exists)
message = "" +"File Already Exists"+"";
else
{
message =ee.ToString();
}
}
}
return message;
}
*/
# endregion
public void ShowAllItems(bool approvestate,bool rejstate,bool pendingstate)
{
}
///
/// Returns the string of a document template URL.
///
/// <param name="strListDocLibray" />
/// <returns>
public string GetDocTemplateUrl(string strListDocLibray)
{
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
if(docLib.DocumentTemplateUrl!=null)
return docLib.DocumentTemplateUrl.ToString();
else
return "";
}
///
/// Not in Use
///
/// <param name="strListDocLibray" />
public void SetDocLibTemplate(string strListDocLibray)
{
web.AllowUnsafeUpdates=true;
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[strListDocLibray];
string str=web.DocTemplates[1].ToString();
docLib.DocumentTemplateUrl="Organization Profile/Forms/template.doc";
web.Update();
}
///
/// Not in Use
///
/// <param name="strDocLibName" />
/// <param name="strFileName" />
/// <param name="approvestate" />
/// <param name="rejstate" />
/// <param name="pendingstate" />
/// <returns>
public string CheckApproval(string strDocLibName,string strFileName,bool approvestate,bool rejstate,bool pendingstate)
{
string message ="";
//strFileName = DropDownList3.SelectedItem.Text
//strDocLibName =DropDownList1.SelectedItem.Text
SPSite site=new SPSite(currentSiteURL);
SPWeb web= site.AllWebs[0];
web.AllowUnsafeUpdates=true;
string url=currentSiteURL+strDocLibName+"/"+strFileName;
SPFile file=web.GetFile(url);
if(approvestate)
{
file.Item.ModerationInformation.Status=SPModerationStatusType.Approved;
file.Item.Update();
try
{
if(!file.Exists)
message="File doesn't exists";
else
{
// file.MoveTo(portalURL+"Approve/"+strFileName);
message = file.Item.ModerationInformation.Status.ToString()+":: Approved" ;
}
}
catch(Exception ee)
{
if( file.Exists==true)
message= ""+"File Already Exists"+"";
else
message =ee.ToString();
}
}
else if (rejstate)
{
file.Item.ModerationInformation.Status=SPModerationStatusType.Denied;
file.Item.Update();
try
{
if(!file.Exists)
message="File doesn't exists";
else
{
// file.MoveTo(portalURL+"Reject/"+strFileName);
message = file.Item.ModerationInformation.Status.ToString()+":: File Rejected" ;
}
}
catch (Exception ee)
{
if(file.Exists)
message = "" +"File Already Exists"+"";
else
{
message =ee.ToString();
}
}
}
else
{
file.Item.ModerationInformation.Status=SPModerationStatusType.Pending;
file.Item.Update();
try
{
if(!file.Exists)
message="File doesn't exists";
else
{
// file.MoveTo(portalURL+"Pending/"+strFileName);
message = file.Item.ModerationInformation.Status.ToString()+"File In PendingList";
}
}
catch (Exception ee)
{
if(file.Exists)
message = "" +"File Already Exists"+"";
else
{
message =ee.ToString();
}
}
}
return message;
}
///
/// This function adds a User to the site or subsite in sharepoint server
///
/// <param name="strDomain" />
/// <param name="strUser" />
/// <param name="strEmailID" />
/// <param name="strUserName" />
/// <param name="strDescription" />
/// <param name="blnReader" />
/// <param name="blnContributor" />
/// <param name="blnAdministrator" />
/// <returns>
public bool CreateUser(string strDomain, string strUser, string strEmailID, string strUserName, string strDescription, bool blnReader, bool blnContributor, bool blnAdministrator)
{
/*site = new SPSite(portalURL);
web = site.AllWebs["sites/" + strSite];
currentSiteURL=portalURL+strSite+"/"; */
//SPWeb spWeb = site.AllWebs[0];
//SPUserCollection spUserCollection = spWeb.Users;
if(blnReader == true)
{
SPRole spRole = web.Roles["Reader"];
spRole.AddUser(strDomain + "\\"+ strUser, strEmailID, strUserName, strDescription);
spRole.Update();
}
if(blnContributor == true)
{
SPRole spRole = web.Roles["Contributor"];
spRole.AddUser(strDomain + "\\"+ strUser, strEmailID, strUserName, strDescription);
spRole.Update();
}
if(blnAdministrator == true)
{
SPRole spRole = web.Roles["Administrator"];
spRole.AddUser(strDomain + "\\"+ strUser, strEmailID, strUserName, strDescription);
spRole.Update();
}
return true;
}
///
/// Deletes a User from the sharepoint server
///
/// <param name="strUser" />
/// <param name="blnReader" />
/// <param name="blnContributor" />
/// <param name="blnAdministrator" />
/// <returns>
public bool DeleteUser(string strUser, bool blnReader, bool blnContributor, bool blnAdministrator)
{
SPRole spRole;
//SPUser user = spRole.Users[strDomain + "\\" + strUser];
if(blnReader == true)
{
spRole = web.Roles["Reader"];
SPUser user = spRole.Users[strUser];
spRole.RemoveUser(user);
}
if(blnContributor == true)
{
spRole = web.Roles["Contributor"];
SPUser user = spRole.Users[strUser];
spRole.RemoveUser(user);
}
if(blnAdministrator == true)
{
spRole = web.Roles["Administrator"];
SPUser user = spRole.Users[strUser];
spRole.RemoveUser(user);
}
return true;
}
//Not in Use
public bool ModifyUser(string strDomain, string strUser, string strEmailID, string strUserName, string strDescription, bool blnReader, bool blnContributor, bool blnAdministrator)
{
SPWeb spWeb = site.AllWebs[0];
SPUserCollection spUserCollection = spWeb.Users;
if(blnReader == true)
{
SPRole spRole = spWeb.Roles["Reader"];
spRole.AddUser(strDomain + "\\"+ strUser, strEmailID, strUserName, strDescription);
spRole.Update();
}
else
{
SPRole spRole = spWeb.Roles["Reader"];
SPUser spUser = spWeb.Users[strDomain + "\\" + strUser];
spRole.RemoveUser(spUser);
spRole.Update();
}
if(blnContributor == true)
{
SPRole spRole = spWeb.Roles["Contributor"];
spRole.AddUser(strDomain + "\\"+ strUser, strEmailID, strUserName, strDescription);
spRole.Update();
}
else
{
SPRole spRole = spWeb.Roles["Contributor"];
SPUser spUser = spWeb.Users[strDomain + "\\" + strUser];
spRole.RemoveUser(spUser);
spRole.Update();
}
if(blnAdministrator == true)
{
SPRole spRole = spWeb.Roles["Administrator"];
spRole.AddUser(strDomain + "\\"+ strUser, strEmailID, strUserName, strDescription);
spRole.Update();
}
else
{
SPRole spRole = spWeb.Roles["Administrator"];
SPUser spUser = spWeb.Users[strDomain + "\\" + strUser];
spRole.RemoveUser(spUser);
spRole.Update();
}
return true;
}
///
/// Not in Use
///
/// <param name="strUser" />
/// <param name="blnReader" />
/// <param name="blnContributor" />
/// <param name="blnAdministrator" />
/// <returns>
public bool RemoveUser(string strUser, bool blnReader, bool blnContributor, bool blnAdministrator)
{
//string strDomain
SPWeb spWeb = site.AllWebs[0];
SPUserCollection spUserCollection = spWeb.Users;
if(blnReader == true)
{
SPRole spRole = spWeb.Roles["Reader"];
SPUser spUser = spWeb.Users[strUser];
spRole.RemoveUser(spUser);
spRole.Update();
}
if(blnContributor == true)
{
SPRole spRole = spWeb.Roles["Contributor"];
SPUser spUser = spWeb.Users[strUser];
spRole.RemoveUser(spUser);
spRole.Update();
}
if(blnAdministrator == true)
{
SPRole spRole = spWeb.Roles["Administrator"];
SPUser spUser = spWeb.Users[strUser];
spRole.RemoveUser(spUser);
spRole.Update();
}
return true;
}
///
/// This function return Users and their roles as a datatable.
///
/// <returns>
public DataTable GetUsers()
{
//SPWeb spWeb = site.AllWebs[0];
SPUserCollection spUserCollection = web.Users;
ArrayList arrListFies = new ArrayList();
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("LoginName");
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("Name");
dt.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("Email");
dt.Columns.Add(dc2);
DataColumn dc3 = new DataColumn("Notes");
dt.Columns.Add(dc3);
DataColumn dc4 = new DataColumn("Roles");
dt.Columns.Add(dc4);
string strSql;
object obj;
foreach(SPUser allusers in spUserCollection)
{
String strRole = "";
dr = dt.NewRow();
dr["LoginName"] = allusers.LoginName;
dr["Name"] = allusers.Name;
dr["Email"] = allusers.Email;
//dr["Notes"] = allusers.Notes;
strSql="select OrganizationName from organizationdata , fc_employee where organizationcode=org_cp_id ";
strSql+=" and username='" + allusers.LoginName + "'";
SPRoleCollection spRoleCollection = allusers.Roles;
obj=SqlHelper.ExecuteScalar(ConfigurationSettings.AppSettings["strCon"],CommandType.Text,strSql);
if(obj!=null)
dr["Notes"]=obj.ToString();
else
{
strSql=" select companyname from cpprofile,fc_employee ";
strSql+= " where cpcode=org_cp_id and username='"+ allusers.LoginName + "'";
obj=SqlHelper.ExecuteScalar(ConfigurationSettings.AppSettings["strCon"],CommandType.Text,strSql);
if(obj!=null)
dr["Notes"]=obj.ToString();
else
dr["Notes"]="";
}
foreach(SPRole spRole in spRoleCollection)
{
if(strRole != "")
strRole = strRole + "," + spRole.Name;
else
strRole = spRole.Name;
}
dr["Roles"] = strRole;
dt.Rows.Add(dr);
}
return dt;
}
///
/// Not in Use
///
/// <param name="strRoleName" />
/// <param name="strDescription" />
/// <returns>
public bool AddRole(string strRoleName, string strDescription)
{
SPWeb spWeb = site.AllWebs[0];
spWeb.Roles.Add(strRoleName, strDescription, SPRights.ManageLists);
spWeb.Update();
return true;
}
///
/// Not in Use
///
/// <param name="strRoleName" />
/// <param name="strDescription" />
/// <returns>
public bool RemoveRole(string strRoleName, string strDescription)
{
SPWeb spWeb = site.AllWebs[0];
spWeb.Roles.Remove(strRoleName);
spWeb.Update();
return true;
}
///
/// Not in Use
///
/// <returns>
public DataTable GetRoles()
{
SPWeb spWeb = site.AllWebs[0];
SPRoleCollection spRoleCollection = spWeb.Roles;
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Name");
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("Description");
dt.Columns.Add(dc1);
foreach(SPRole spRoles in spRoleCollection)
{
dr = dt.NewRow();
dr["Name"] = spRoles.Name;
dr["Description"] = spRoles.Description;
dt.Rows.Add(dr);
}
return dt;
}
# region Workflow
///
/// Returns the Guid associated with the Document Libary
///
/// <param name="docLibName" />
/// <returns>
public System.Guid GetDocLibGUID(string docLibName)
{
string strTemp;
int iStartIndex,iEndIndex,iLength;
System.Guid guid;
web.AllowUnsafeUpdates = true;
iStartIndex=docLibName.IndexOf(">")+1;
if(iStartIndex>0)
{
iEndIndex=docLibName.IndexOf("(");
iLength=iEndIndex-iStartIndex;
strTemp=docLibName.Substring(iStartIndex,iLength);
guid=web.Lists[strTemp.Trim()].ID;
}
else
{
guid = web.Lists[docLibName].ID;
}
return guid;
}
///
/// Returns the Document Templates in a site
///
/// <returns>
public ArrayList GetDocumentTemplates()
{
ArrayList arrDocTemplates=new ArrayList();
SPDocTemplateCollection docTemps = web.DocTemplates;
foreach (SPDocTemplate docTemp in docTemps)
{
arrDocTemplates.Add(docTemp.Name);
}
return arrDocTemplates;
}
///
/// Not in Use
///
/// <param name="docLibName" />
/// <param name="fileName" />
/// <returns>
public int AddFileAppList(string docLibName,string fileName)
{
System.Guid DocLibGuid=GetDocLibGUID(docLibName);
objCon=new SqlConnection("server=dev206;database=devs;uid=sa;pwd=sa");
string strCmdInsert="insert into AppList(doclibid,username,filename,status) select doclibid,username,'"+ fileName + "','pending' from AppListForDocumentLib where doclibname='"+ docLibName + "'";
objCmd=new SqlCommand(strCmdInsert,objCon);
if(objCon.State==ConnectionState.Closed)
objCon.Open();
int iStatus=Convert.ToInt32(objCmd.ExecuteNonQuery());
objCon.Close();
return (iStatus);
}
///
/// Not in Use
///
/// <param name="strSiteName" />
/// <returns>
public SPAlertCollection AlersOnSite(string strSiteName)
{
// SPSite site = new SPSite(portalURL + strSiteName);
// SPWeb web = site.AllWebs[0];
SPAlertCollection AlertCol = web.Alerts;
// ArrayList arrListAlerts = new ArrayList();
// foreach(SPAlert al in AlertCol)
// {
// arrListAlerts.Add(al);
// }
return AlertCol;
}
///
/// Changes the file status with new status specified.
///
/// <param name="strDocLibName" />
/// <param name="strFileName" />
/// <param name="status" />
/// <returns>
public bool ChangeFileStatus(string strDocLibName,string strFileName,string status)
{
web.AllowUnsafeUpdates=true;
string url=currentSiteURL+strDocLibName+"/"+strFileName;
// HttpContext.Current.Response.Write(url);
// HttpContext.Current.Response.End();
SPFile file=web.GetFile(url);
if(status=="0")
{
file.Item.ModerationInformation.Status=SPModerationStatusType.Approved;
file.Item.Update();
}
else if(status=="1")
{
file.Item.ModerationInformation.Status=SPModerationStatusType.Denied;
file.Item.Update();
}
else if(status=="2")
{
file.Item.ModerationInformation.Status=SPModerationStatusType.Pending;
file.Item.Update();
}
return true;
}
///
/// Not in Use
///
/// <param name="userName" />
/// <param name="docLibGuid" />
public void GetDBAppList(string userName,System.Guid docLibGuid)
{
/*string strSql="select Filename from AppList where doclibid='"+ docLibGuid.ToString() +" ' and username='"+ userName + "' and status='approved'";
objCon=new SqlConnection("server=dev206;database=devs;uid=sa;pwd=sa");
objCmd=new SqlCommand(strSql,objCon);
DataSet ds=new DataSet();
DataTable dt=new DataTable("AppList");
// DataColumn dCol=new DataColumn("id",typeof(System.Int32));
// dCol.AutoIncrementSeed=1;
// dCol.AutoIncrement=true;
// dt.Columns.Add(dCol);
DataColumn dCol1 = new DataColumn("Document",typeof(System.String));
dt.Columns.Add(dCol1);
DataColumn dCol2 = new DataColumn("Status",typeof(System.String));
dt.Columns.Add(dCol2);
DataColumn dCol3 = new DataColumn("CheckInStatus",typeof(System.String));
dt.Columns.Add(dCol3);
ds.Tables.Add(dt);
SPSite site = new SPSite(portalURL);
SPWeb web = site.AllWebs[0];
dr = dt.NewRow();
dr["Document"] = item.File.Name;
string k = item.File.Name;
dr["Status"] = item.ModerationInformation.Status.ToString();
string url= currentSiteURL + strListDocLibray +"/"+ item.File.Name;
SPFile fileCheck=web.GetFile(url);
string strStatus = fileCheck.CheckOutStatus.ToString();
if(strStatus.ToString().ToUpper() == "NONE")
{
dr["CheckInStatus"] = "";
}
else
{
string strCheckedOutBy = fileCheck.CheckedOutBy.LoginName;
dr["CheckInStatus"] = "Checked Out BY " + strCheckedOutBy;
}
dt.Rows.Add(dr);
}
DataColumn [] pKeys=new DataColumn[1];
pKeys[0]=ds.Tables[0].Columns["FileName"];
ds.Tables[0].PrimaryKey=pKeys;
objDa=new SqlDataAdapter(objCmd);
objDa.Fill(ds.Tables["AppList"]);
return ds;*/
}
///
/// Not in Use
///
/// <param name="docLibGuid" />
/// <returns>
public DataSet GetDBUserList(System.Guid docLibGuid)
{
string strSql="select UserName from AppListForDocumentLib where doclibid='"+ docLibGuid.ToString() +"'";
objCon=new SqlConnection("server=dev206;database=devs;uid=sa;pwd=sa");
objCmd=new SqlCommand(strSql,objCon);
DataSet ds=new DataSet();
DataTable dt=new DataTable("UserList");
DataColumn dCol1=new DataColumn("UserName",typeof(System.String));
dt.Columns.Add(dCol1);
ds.Tables.Add(dt);
DataColumn [] pKeys=new DataColumn[1];
pKeys[0]=ds.Tables[0].Columns["UserName"];
ds.Tables[0].PrimaryKey=pKeys;
objDa=new SqlDataAdapter(objCmd);
objDa.Fill(ds.Tables["UserList"]);
return ds;
}
///
/// Returns all the documents that requires approval.
///
/// <param name="docLibGuid" />
/// <param name="ReportingAuthority" />
/// <param name="status" />
/// <returns>
public DataSet GetDBPendingDocs(string docLibGuid,string ReportingAuthority,string status)
{
string strSql="select FileName from FILEAPPROVERS where doclibid='"+ docLibGuid.ToString() +"' and ReportingAuthority='" + ReportingAuthority.Trim() + "' and status='" + status + "'";
// HttpContext.Current.Response.Write(strSql);
// HttpContext.Current.Response.End();
objCon=new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
objCmd=new SqlCommand(strSql,objCon);
DataSet ds=new DataSet();
DataTable dt=new DataTable("FileList");
DataColumn dc = new DataColumn("FileName");
dt.Columns.Add(dc);
ds.Tables.Add(dt);
objDa=new SqlDataAdapter(strSql,objCon);
objDa.Fill(ds.Tables["FileList"]);
return ds;
}
///
/// Updates the status of the file with the new status
///
/// <param name="strDocLibId" />
/// <param name="strFileName" />
/// <param name="strRepAuth" />
/// <param name="status" />
/// <returns>
public bool UpdateApprovalStatus(string strDocLibId,string strFileName,string strRepAuth,string status)
{
string strUpd="update FILEAPPROVERS set status='"+ status + "' where doclibid='"+ strDocLibId +"' and FileName='"+ strFileName + "' and ReportingAuthority='" + strRepAuth + "'" ;
objCon=new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
objCmd=new SqlCommand(strUpd,objCon);
if(objCon.State==ConnectionState.Closed)
objCon.Open();
// HttpContext.Current.Response.Write(strUpd);
// HttpContext.Current.Response.End();
objCmd.ExecuteNonQuery();
return true;
}
///
/// Returns the File Status
///
/// <param name="strFileName" />
/// <param name="IsCheckInStatus" />
/// <returns>
public string GetFileStatus(string strFileName,bool IsCheckInStatus)
{
string url= currentSiteURL + strFileName;
SPFile file=web.GetFile(url);
SPListItem item=file.Item;
// HttpContext.Current.Response.Write("CustomStatus:"+file.Properties["CustomStatus"].ToString());
// HttpContext.Current.Response.End();
//HttpContext.Current.Response.Write("CustomStatus");
if(IsCheckInStatus)
return file.CheckOutStatus.ToString();
else
return item["Approval Status"].ToString();
}
#endregion
public void ErrorLog(string modName, string sErrMsg)
{
// string sYear = DateTime.Now.Year.ToString();
// string sMonth = DateTime.Now.Month.ToString();
// string sDay = DateTime.Now.Day.ToString();
// string sErrorTime = sYear+sMonth+sDay;
// string sLogFormat = DateTime.Now.ToShortDateString().ToString()+" "+DateTime.Now.ToLongTimeString().ToString()+" ==> ";
// string sPathName = "E://Projects/Logs/";
// StreamWriter sw = new StreamWriter(sPathName+sErrorTime+modName,true);
// sw.WriteLine(sLogFormat + sErrMsg);
// sw.Flush();
// sw.Close();
}
///
/// Fills the drop down list given the dropdown and Sql Query
///
/// <param name="ddl" />
/// <param name="strSql" />
/// <param name="strValueField" />
/// <param name="strTextField" />
public void FillDropDown(DropDownList ddl,string strSql,string strValueField,string strTextField)
{
//Filling Drop Down List box
// SqlConnection objCon;
// objCon=new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
//SqlDataAdapter
objDa=new SqlDataAdapter(strSql,ConfigurationSettings.AppSettings["strCon"]);
DataSet objDs=new DataSet();
objDa.Fill(objDs);
ddl.DataSource=objDs;
ddl.DataTextField=strTextField;
ddl.DataValueField=strValueField;
ddl.DataBind();
ddl.Items.Insert(0,"-Select-");
objDa.Dispose();
if(ddl.Items.Count == 2)
ddl.SelectedIndex = 1;
}
///
/// Fills the drop down list given the dropdown and Stored Procedure
///
/// <param name="ddl" />
/// <param name="storedprocedure" />
/// <param name="strValueField" />
/// <param name="strTextField" />
public void FillDropDownList(DropDownList ddl,string storedprocedure,string strValueField,string strTextField)
{
try
{
objCon=new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
if(objCon.State==ConnectionState.Closed)
objCon.Open();
objCmd.CommandType =CommandType.StoredProcedure;
objCmd.CommandText = storedprocedure;
objCmd.Connection =objCon;
objDs=new DataSet();
objDa =new SqlDataAdapter(objCmd);
objDa.Fill(objDs);
ddl.DataSource=objDs;
ddl.DataTextField=strTextField;
ddl.DataValueField=strValueField;
ddl.DataBind();
ddl.Items.Insert(0,"-Select-");
objDa.Dispose();
objCon.Close();
}
catch(Exception ee)
{
}
}
///
/// Not in use
///
/// <param name="InsertOrUpdate" />
/// <param name="Id" />
/// <param name="strTitle" />
/// <param name="strDescription" />
/// <param name="strAssignedTo" />
/// <param name="strPriority" />
/// <param name="strStatus" />
/// <param name="strPerCompleted" />
/// <param name="dtStart" />
/// <param name="dtEnd" />
public void AddTask(bool InsertOrUpdate,string Id,string strTitle,string strDescription,string strAssignedTo,string strPriority,
string strStatus,string strPerCompleted,string dtStart,string dtEnd)
{
//Adding Tasks to the site
web.AllowUnsafeUpdates=true;
SPList list = web.Lists["Tasks"];
SPListItemCollection listItems = list.Items;
SPListItem listItem;
if(!InsertOrUpdate) //Insert
listItem = listItems.Add();
else //Update
//if(Id != null)
listItem = listItems.GetItemById(Convert.ToInt32(Id));
listItem["Title"] = strTitle; //"Testing Task Properties";
listItem["Description"]=strDescription; //"Description";
if(strAssignedTo != null)
listItem["Assigned To"] = web.Users[strAssignedTo]; //web.Users["HOL_DEV\\prasanth.kharade"];
listItem["Priority"] = strPriority; //"High";
listItem["Status"] = strStatus; //"Deferred";
listItem["% Complete"] = strPerCompleted; //.7;
if(dtStart != null)
listItem["Start Date"]= Convert.ToDateTime(dtStart); //DateTime.Now;
if(dtEnd != null)
listItem["Due Date"]= Convert.ToDateTime(dtEnd); //DateTime.Now;
listItem.Update();
Close();
}
///
/// Not in Use
///
/// <returns>
public DataTable GetTasks()
{
SPList list = web.Lists["Tasks"];
SPListItemCollection listItems = list.Items;
return listItems.GetDataTable();
}
///
/// Closes the web site
///
public void Close()
{
//Close Site and Web objects.
web.Close();
web.Dispose();
site.Close();
site.Dispose();
}
///
/// Returns all the pending documents for a particular user in a document library.
///
/// <param name="sUserName" />
/// <param name="guid" />
/// <returns>
public int GetPendingDocCount(string sUserName,string guid)
{
//DataSet GetDBPendingDocs(string docLibGuid,string ReportingAuthority,string status)
DataSet ds=this.GetDBPendingDocs(guid.ToString(),sUserName,"pending");
return ds.Tables[0].Rows.Count;
}
///
/// Binds the Ultra webtree with the folders
///
/// <param name="objTree" />
public void BindTreeApprovals(Infragistics.WebUI.UltraWebNavigator.UltraWebTree objTree)
{
string strFolderName="";
SPFolderCollection folderCol,folderCol1;
int i=0;
int iFileCount=0;
System.Guid guid;
web.AllowUnsafeUpdates=true;
folderCol=web.Folders;
foreach(SPFolder folder in folderCol)
{
folderCol1=folder.SubFolders;
if(folder.Name.ToString().Substring(0,1)!="_" && folder.Name.ToString()!="" && folder.Name.ToString().ToLower()!="lists" && folder.Name.ToString().ToLower()!="images")
{
guid=this.GetDocLibGUID(folder.Name.ToString());
iFileCount=this.GetPendingDocCount(HttpContext.Current.Session["UserName"].ToString(),guid.ToString());
if(iFileCount>0)
objTree.Nodes.Add("" + folder.Name.ToString()+ " (" + iFileCount + ")",web.Url+"/"+folder.Url);
else
objTree.Nodes.Add(folder.Name.ToString(),web.Url+"/"+folder.Url);
foreach(SPFolder folder1 in folderCol1)
{
strFolderName=folder1.Name.ToString();
iFileCount=this.GetPendingDocCount(HttpContext.Current.Session["UserName"].ToString(),guid+ "/" + folder1.Url);
if(strFolderName.Substring(0,1)!="_" && strFolderName!="" && strFolderName.ToLower()!="lists" && strFolderName.ToLower()!="images" && strFolderName.ToLower()!="forms")
{
if(iFileCount>0)
objTree.Nodes[i].Nodes.Add("" +folder1.Name.ToString()+ " (" + iFileCount + ")",web.Url+"/"+folder1.Url);
else
objTree.Nodes[i].Nodes.Add(folder1.Name.ToString(),web.Url+"/"+folder1.Url);
}
}
i=i+1;
}
}
}
///
/// Binds all the folders to a Ultra Webtree
///
/// <param name="objTree" />
public void BindTree(Infragistics.WebUI.UltraWebNavigator.UltraWebTree objTree)
{
string strFolderName="";
SPFolderCollection folderCol,folderCol1;
web.AllowUnsafeUpdates=true;
folderCol=web.Folders;
int i=0;
foreach(SPFolder folder in folderCol)
{
folderCol1=folder.SubFolders;
if(folder.Name.ToString().Substring(0,1)!="_" && folder.Name.ToString()!="" && folder.Name.ToString().ToLower()!="lists" && folder.Name.ToString().ToLower()!="images")
{
objTree.Nodes.Add(folder.Name.ToString(),web.Url+"/"+folder.Url);
foreach(SPFolder folder1 in folderCol1)
{
strFolderName=folder1.Name.ToString();
if(strFolderName.Substring(0,1)!="_" && strFolderName!="" && strFolderName.ToLower()!="lists" && strFolderName.ToLower()!="images" && strFolderName.ToLower()!="forms")
{
objTree.Nodes[i].Nodes.Add(folder1.Name.ToString(),web.Url+"/"+folder1.Url);
}
}
i=i+1;
}
}
}
}
}
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshres
http://himabinduvejella.blogspot.com
|
|
|
|
|
Hello All!
This is a general question and I was confused that on which forum I ask. My product is in C# so it chose this.
The problem is that we have some forms on which the control data is populated from the database. Now we need to check for the data coming from database with certian IF statements and then fill the respective controls(textboxes). We are getting the dataset.
Now my team member says that we should first put all the dataset Row data into private variables and then perform IF on Private variables and then populate the control with private variables. This is coz it is difficult to write (ObjDataSet.Tables[0].Rows[index]["SomeCol"]) than simply the VariableName in the checks.
Now we can have 15-20 columns in a dataset Row, and thus we have to declare 15-20 variables in each form.......Is this approach suitable.....? Please suggest.
Thanx in advance
Mubashir,
Remote Silicon
|
|
|
|
|
There's nothing wrong with pulling the data from the row into variables, though your database, business logics and maybe user interface are all intervined together.
But IMO what is better is pulling the data from the row into variables of a class.
For example
public class Customer
{
// your private declaration of the variables ie customer name, address, phone
// the public accessors of the private variables
public validatecustomer();
public void setcustomer(DataRow row);
public DataRow Row
{
get;
}
}
As what you can see, you can add functionalities to the customer class such as populating it by passing it a row, or get the customer as a DataRow, validating it, binding the properties (variable) to controls.
It is an object oriented and 2 tier way of doing it, which separate your logics and database from each others.
-- modified at 2:45 Wednesday 22nd March, 2006
|
|
|
|
|
Hello,
The two tier approach is asking for trouble in a multi-user application. The approach lacks maintanability since the business logic and the database access is spread across the GUI. A better approach is using at least another layer with your business logic and one layer with your database access code. The principle is to use mappers for your domain objects that shift the data from and to the database and the domain objects for the business logic. The GUI just uses the domain objects. It is a lot of work to get it started, but in the end it pays of when it comes to maintaining and reusing the code.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hello,
How you solve the problem, or if you solve it at all is just a matter of preference. It is indeed tedious to write and it obfuscates your statements. My advice is to create a wrapper class that wraps a row of your database. This can be a simple replacement around the long prefex:
public class SomeWrapper
{
public object GetCol(string colName)
{ return ObjDataSet.Tables[0].Rows[index]["SomeCol"]; }
}
Or the wrapper can be a more sophisticated using properties and the like. You can use the wrapper the following way:
SomeWrapper row = new SomeWrapper(ObjDataSet.Tables[0].Rows[index]);
if( row.GetCol("column...").Equals("SomeValue) )
{
// your logic
}
Hope this helps
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
There is definitely more than one way to skin the proverbial cat.
My take is create a named data set. The when you fill the adapter you are referring to a table and row such as MyTable.AccountNumber[i] instead of Tables[0].Rows[....]
If you have signaficant converion between the dataset and the deseried representation in variables then a custom data set make not fit so well. You might be better off dealing with the generic data set.
But again I would rather define an Interface with the constants you need to manage the generic data set. Then you can refer to logical index names instead the hard coded table, row or column names.
Finally when should you copy the data set to a private data store? Well if the data set is humongous and you are only using a small portion that has to be converted and used by other .CS classes and modules, then it makes sense. Particularly if
If you are copying the data set and using the variables all with one class the need is dubious. It is definitely "overhead" to copy a bunch of variables so if you can find a way to directly operate on the data perhaps via a Named Data Set or through an Interface, then your app can drive directly off the data w/o the intermmediate cyles.
Good Luck
Mike Luster
CTI/IVR/Telephony SME
|
|
|
|
|
How can I Show/Hide Quick Launch Toolbar from my C# Application. If someone have written the code for it then Please send me.
-- modified at 2:43 Wednesday 22nd March, 2006
|
|
|
|
|
|
BUt I just want to show/hide Quick Launch bar as it happens in
TaskBar(Right Click)-->Toobar-->Quick LaunchBar.
Id you have some idea about that then please mail me.
|
|
|
|
|
I'm trying something new...
I'm using Visual Studio 2005 and I have an application that uses a combo box, a datagrid and a report viewer. Here's my brain fart...
I want to use the combobox to select a company and from that selection, the datagrid populates with only the details from an sql database that is linked to the company id field in the combobox.
Problem: How do I build the datagrid that allows me to select certain rows to send to a report. I know this may seem like a tall order but I'm just have a major creative block! Any help would be greatly appreciated.
Regards.
JB
|
|
|
|
|