There are a system stored procedure sp_who which returns information regarding current sessions on given database.
There is an extended version of this stored procedure is also available.
public static void ProcessError(Exception exception, string otherDetails = "")
{
StackTrace stackTrace = new StackTrace();
string methodName = stackTrace.GetFrame(1).GetMethod().Name;
string className = stackTrace.GetFrame(1).GetMethod().DeclaringType.Name;
string classDetail = string.Format("{0}.{1}", className, methodName);
string exceptionDetail = string.Format("Error occurred in {0}. {1}Message:{2}",
classDetail,
Environment.NewLine,
exception.Message
);
if (!string.IsNullOrWhiteSpace(otherDetails))
{
exceptionDetail = string.Format("{0}{1}Other Details: {2}.",
exceptionDetail,
Environment.NewLine,
otherDetails
);
}
// send this detail for saving
LogError(exceptionDetail);
}
// to get name of calling method
string methodName = stackTrace.GetFrame(1).GetMethod().Name;
// to get name of calling class
string className = stackTrace.GetFrame(1).GetMethod().DeclaringType.Name;
Now lets decide where to save this detail
public enum LogMethods
{
Database,
File,
Email
};
...
...
public static void LogError(string exceptionDetail)
{
switch (errorLogMethod)
{
case LogMethods.Database:
LogErrorInDatabase(exceptionDetail);
break;
case LogMethods.File:
LogErrorInFile(exceptionDetail);
break;
case LogMethods.Email:
SendErrorLog(exceptionDetail);
break;
case default:
SendErrorLog(exceptionDetail);
break;
}
}
Now last step, implement save methods
public static void logErrorMessageInDB(string exceptionDetail, string methodName)
{
try
{
MyDataContext myDC = DataContext;
Log lerror = new Log
{
FullDescription = exceptionDetail,
MethodName = methodName,
CreateDataTime = DateTime.Now
};
iDC.Log.InsertOnSubmit(lerror);
iDC.SubmitChanges();
}
catch (Exception exp)
{
/*
LogErrorInFile(exp);
// OR
LogErrorInEventLog(exp);
*/
}
}
From last few months I am working with InfoPath forms; especially for web hosted
forms. I needed to create a page to host InfoPath form. Here is a quick tutorial
to do this
Assumptions:
We need to do few tasks
So let’s get started.
1. 2. From various options on right side of page, Select “SharePoint Server” (Publish
form to a SharePoint Library). This will open Publishing Wizard dialog.
1. 3. In Publishing Wizard dialog type URL of SharePoint server where you want to
host this InfoPath form and click Next.
1. 5. Select location where you want to publish your InfoPath form; (Please make
sure that SharePoint admin can access this location) and hit Next.
1. 8. After you click on publish it may take few minutes to update screen, Once
published you will see confirmation screen indicating that publication was successful.
Click on Close to finish “Publishing Wizard”
Now Our InfoPath form is ready for publication on SharePoint server. First we need
to upload InfoPath form on server. For that …
2. 1. Open SharePoint website on web browser and select “Site Settings” from Site
Actions menu. (top left side)
2. 2. a) This will open central Administration screen, From left side list, Select
“General Application Settings.”
2. 2. b) When selected (General Application Settings) you will see list of settings
options on right side, Select “Manage Form Template” from InfoPath Forms Services.
(Assuming InfoPath Forms Services is installed and available)
2. 3. You will see list of available InfoPath forms. On top of the page you will
see link for uploading form template
2. 4. From upload page click on browse and select the file we saved in Step 5 of
first section and click Upload
2. 5. Once form is uploaded you will see confirmation message. By clicking OK you
will be redirected to Template management page where you will see your form on list.
2. 6. Select your form and open options menu (when you move your cursor to right
side of forms name you will see dropdown box click there which will open options
menu) and select “Activate to a Site Collection” option.
Now we have InfoPath form available on SharePoint site; we need to make it accessible
to end user for data entry. First of all (assuming we don’t have one) we need to
create a new page to host InfoPath form.
3. 1. To be able to do this open SharePoint website in web browser and select “New
Page” from Site actions menu. (top left)
3. 5. From list of available types select the InfoPath from you want to add and
click on “Add” button. Once done click OK to save your changes.
3. 7. From Categories select “Forms”, From Web Parts select “InfoPath Form web part”
and click “Add”
3. 10. (optional) By default any InfoPath webpart will appear with header, In some
cases you don’t need header, to remove header expand “Appearance” section and select
“None” from Chrome Type. Which will remove header.
3. 11. Once done Click Apply and your page is ready. You can publish it (after any
other formatting related changes you may want to do)
Happy Coding !!! :)
Few days back I needed to join few (Thousand) text file as One file. I thought of
several options
I remembered earlier (dark) days of DOS (Dirty Operation System) when screen was
black and text was white, everything was between 32 rows and 80 columns. Few of
DOS commands were very interesting like | (more) and > or >> (pipe). I thought to
do an experiment with that. I went to DOS prompt in same directory where all .txt
files were stored and used following command
and ...
Yes !!! I got combined file named MergetFile.txt which was 14GB. There are few more
tricks like this
This will join FirstFile.txt, SecondFile.txt, ThirdFile.txt and fifthFile.txt into
MergedFile.txt, this is useful when you want to join files in certain order.
Please note that each file is separated by a space. As you may already know, if
are in different folders please use full path instead of just file name.
This will first join all files with .txt extension and then will join all files
with .csv extension to create a file called MergedFile.txt Here the magic command
is > which takes output of left side command and gives as input to right side command.
If used as >> then output gets be appended. As stated in
the principal of "Occam's razor" "The simplest explanation is
most likely the correct one"
Instead of writing my own code (spending few hours) or download or buy 3rd party
tool (spending money earned in few hours !!!) I used DOS to do the work. Hope this
helps Enjoy coding !!!