Sunday, January 29, 2006

Right click command prompt

Here's a handy tip that I got from a co-worker, who found it in the book Microsoft Visual C# .NET Step by Step. It creates a shortcut in the right click context menu of Windows Explorer to open a command prompt in the current directory. When I need to run scripts in a very long directory name, this is very handy.

So here's how you set it up:

Open up windows explorer
Tools -> Folder Options.
File Types Tab
Select the Folder file type
Click Advanced
Click New
For the Action type what ever you want the context menu to display, I used Command Prompt.
For the Application used to perform the action use c:\windows\system32\cmd.exe (note on win2k you will want to specify the winnt directory instead of the windows directory)

You can also use this feature to attach context actions to file types. Or if you want to create a right click open with option for any file type (for instance I like to be able to open any file with notepad, see: my blog entry here.

Friday, January 20, 2006

Arrays

Well I guess it is time to start being a true programmer and master arrays. So what did I learn day one about using arrays.

If you are going to use C# and want a dynamic array you better use the following code... (HINT USE AN ARRAY LIST)

int i = 0;
ArrayList al = new ArrayList();
while (myReader.Read())
{
al.Add(myReader.GetInt32(0));
i = i + 1;
}

Friday, January 13, 2006

Directory .NET Functions

NET Framework Class Library

Directory Members

Moojjoo Blog

SharePoint Stats

Getting Usage Statistics on Sharepoint Portal 2003 Areas
This comes from this microsoft blog



"There are pages available in Windows SharePoint Services that will allow you to obtain usage statistics for WSS Sites. However, this is not the case for Areas in SharePoint Portal Server 2003. There are no built-in hyperlinks in the Admin pages for viewing usage statistics for a give Area.

Does this mean that usage statistics are not available for Areas in SPS 2003? No, it just means that you have to know a backdoor URL to get to the pages that display the stats. Here is the format of the URL:

http://{your portal name}/_layouts/1033/usageDetails.aspx

This URL will take you to a usage statistics page for the Home Area of your portal. (Note: the 1003 is the designator for you language, so it will be different if not using U.S. English).

If you want to look at usage statistics for a Subarea, for instance, News, you would modify the URL to look as follows:

http://{your portal name}/News/_layouts/1033/usageDetails.aspx"


Moojjoo Blog

Wednesday, January 11, 2006

Validating Edits in Grids

When using the Grid Web Controld a lot of times I find myself needing to customize the edit functionality to use validation. The following are the procedures that I use to customize the Data Grid Web Controld.

In order to implement a customization in a datagrid you need to implement a template

<asp:TemplateColumn HeaderText="Gift Amount">
<itemtemplate>
<asp:label id="lblAward_Amount" text='<%# DataBinder.Eval(Container.DataItem, "Gift_Amount", "{0:c}") %>' Runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:textbox ID="txtGift_Amount2" text='<%# DataBinder.Eval(Container.DataItem, "Gift_Amount", "{0:c}") %>' runat="server" />
<asp:regularexpressionvalidator id="Regularexpressionvalidator1" runat="server" ControlToValidate="txtGift_Amount2"
ErrorMessage="Money Values only example 20.00 no commas!" ValidationExpression="\d*.\d{2}"></asp:regularexpressionvalidator></asp:boundcolumn>
</edititemtemplate>
</asp:TemplateColumn>

To access this in the code behind you must using the following:

// This will access the control inside the data grid.
tempGiftAmount = (((TextBox)e.Item.FindControl("txtGift_Amount2")).Text);

Wednesday, December 28, 2005

Inserting Null Values into SQL Server "FINALLY"

After many months of frustration I finally discovered the code to post null values into SQL Server.

cmd.Parameters.Add("@Emp_EID", System.DBNull.Value);

Tuesday, November 01, 2005

Validating Multi-line text boxes in ASP.NET using regular expression validator

Validate Multi-line text box in ASP.NET with Regular Expression

^[\s\S]{0,200}$

200 is the Character count

Thursday, October 20, 2005

Friday, October 07, 2005

Custom Validation

Today I created my first custom validation:

public void TextFilled(object sender, ServerValidateEventArgs e)
{
int counter = 0;
if(DropDownList_Awards.SelectedValue.ToString() == "4" && AwardDesc.Text == "")
{
counter++;
}
e.IsValid = (counter == 0) ? true : false;
}

Hower, I made a bad error: DUH!!!!

on the Button Click event add

if (Page.IsValid)
{

}

Tuesday, September 27, 2005

Thursday, September 15, 2005

spcontnt.aspx

Don't forget spcontnt is your key for 'web part' error resolution

Submitted By: Riwut Libinuko, Plasmedia
Posted On: 1/13/2005

Overall Rating: 3 (1 ratings, 1 comments)


Description:
Eventough webpart is very powerfull, but debuging web part is painfull. For example, you forget to put try-catch block in your code - and one day you get error without any clue to edit. Or imagine, you're creating on-the-fly graph web part, and send wrong HTML header to the page. Causing Sharepoint page shows image only and no interface to access.

What should we do ?

Remember that Sharepoint has spcontnt.aspx - an interface to edit web farm content,

http://[YOURSITES/_layouts/1033/spcontnt.aspx?&url=[FULLYENCODED_WEBFARMPAGE]

Change [YOURSITES] to url of your site, and [FULLYENCODED_WEBFARMPAGE] to url to your web farm.aspx page.

Then, close the offending web part.

Wednesday, September 14, 2005

Compiler Error Message: CS0006: Metadata file

Resolution that is working so far however if this starts happening again I will let everyone know.

I saved my solution. Shut down VS.NET deleted the temp folder: 'c:\windows\microsoft.net\framework\v1.1.4322\temporary asp.net\files\wow
Reset IIS.

Seems to have cleared up for now.



"Moojjoo" wrote:

> Has anybody else ever seen this problem and know how to resolve it?
>
> Sometimes my app will load and debug other times I get the following:
>
> Compilation Error
> Description: An error occurred during the compilation of a resource required
> to service this request. Please review the following specific error details
> and modify your source code appropriately.
>
> Compiler Error Message: CS0006: Metadata file
> 'c:\windows\microsoft.net\framework\v1.1.4322\temporary asp.net
> files\wow\7a057e9f\806dc5a7\assembly\dl2\da5089d2\a8835932_a2b8c501\rjrt.wow.rules.dll' could not be found
>
> Source Error:
>
>
>
> [No relevant source lines]
>
>
> Source File: Line: 0
>
>
>

Monday, September 12, 2005

Moving a Solution you are developing from one server to another

When moving your sites from one server to another be sure to update all you references to your server. The best way that I found for doing this was using a find and replace.

Two files that make a big difference are the AppID.csproj.webinfo and AppID.sln files

Friday, August 05, 2005

SharePoint Document Library Icons

SharePoint: Adding icons for other document types (like PDF)
I've seen lots of questions on various SharePoint newsgroups about how to get PDF files to show up with the right icon in document libraries. The process is documented in the WSS admin guide, but it's not that easy to find. I'm working with the folks in PSS/Product Team to try to get a KB article on this topic. In the meantime, though, here it is:

At a high level, all you need to do is get the icon into the \template\images directory, and then map the extension to the icon in \template\xml\docicon.xml. Then you reset IIS, and voilà, you have your mapping.

So, let's say you've already dropped icpdf.gif into the \template\images directory. You would then modify docicon.xml to add the mapping that points to the icon (in bold below):

<DocIcons> <ByProgID> <Mapping Key="Excel.Sheet" Value="ichtmxls.gif"/> <Mapping Key="PowerPoint.Slide" Value="ichtmppt.gif"/> <Mapping Key="Word.Document" Value="ichtmdoc.gif"/> </ByProgID> <ByExtension> <Mapping Key="doc" Value="icdoc.gif"/> <Mapping Key="gif" Value="icgif.gif"/> <Mapping Key="htm" Value="ichtm.gif"/> <Mapping Key="html" Value="ichtm.gif"/> <Mapping Key="ppt" Value="icppt.gif"/> <Mapping Key="pdf" Value="icpdf.gif"/> </ByExtension></DocIcons>
Now, let's say you also want to add a new default icon for unknown file types, called icunk.gif. Again, you'd drop the icon in the \template\images directory, but this time you'd modify docicon.xml to add a default value that is used if a matching can't be made by ProgID or Extension (in bold below):

<DocIcons>
<ByProgID>
<Mapping Key="Excel.Sheet" Value="ichtmxls.gif"/>
<Mapping Key="PowerPoint.Slide" Value="ichtmppt.gif"/>
<Mapping Key="Word.Document" Value="ichtmdoc.gif"/>
</ByProgID>
<ByExtension>
<Mapping Key="doc" Value="icdoc.gif"/>
<Mapping Key="gif" Value="icgif.gif"/>
<Mapping Key="htm" Value="ichtm.gif"/>
<Mapping Key="html" Value="ichtm.gif"/>
<Mapping Key="ppt" Value="icppt.gif"/>
<Mapping Key="pdf" Value="icpdf.gif"/>
</ByExtension>
<Default>
<Mapping Value="icunk.gif"/>
</Default>
</DocIcons>

Happy mapping, and don't forget to restart IIS when you're done!

Resource: http://blogs.msdn.com/lauraj/archive/2004/01/21/61187.aspx

Wednesday, August 03, 2005

Streaming images from memory

Well fellow .NET developers I thought you would find this article very helpful. Thanks Troy Tucker for the code snippet on getting the image to stream from memory:

ASP.NET: Create Snazzy Web Charts and Graphics On the Fly with the .NET Framework -- MSDN Magazine, February 2002: http://msdn.microsoft.com/msdnmag/issues/02/02/ASPDraw/ Article is awesome…
//NEW CODE for displaying IMAGE from MEMORY
MemoryStream myStream;
Byte[] imgByte = (Byte[])myCollection;

myStream = new MemoryStream(imgByte);
System.Drawing.Image _image = System.Drawing.Image.FromStream(myStream);

//System.Drawing.Image _newimage = _image.GetThumbnailImage(,, null, new System.IntPtr());
Response.ContentType = "image/jpeg"; //Make sure this is not jpg instead of jpeg!!!!!!!!!!
_image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

Monday, July 25, 2005

DataGrid ItemCommand not firing

# re: DataGrid Paging Events not firing 7/25/2005 3:10 PM Moojjoo
Well everyone... Thank you. I read everybody's response and everyone helped out. My problem was with the ItemCommand Event not firing..

Solutions... Use a link instead of a button worked, but since I am developing for a client I must make everything look the same and use a button. Yes I did copy the code from another Grid that was working and have been scratching my head until I found this site "Thank you GOD".

Solution to fix all...

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack )
{
DataGrid.DataBind();
}
}

What a waste of developer time... ARGH I am dying on my time left on my project...

On to solving streaming an image loaded from Active Directory to a object in memory to presenting it to the end user inside a datalist...

.NET got to love it. 2 more years I should be at the professional level and quote my price for hourly wages... LOL....



Wednesday, July 20, 2005

ADO.NET Accessing Data in a DataSet > DataTable > DataRow

Good Stuff if you return one row from the database.

string strSQL_Table = "Update_Employee";
// Populate Text Boxes with data
txtEmpLanID.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[0].ToString();
txtEmpFirstName.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[1].ToString();
txtEmpLastName.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[2].ToString();
txtEmpNumber.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[3].ToString();
txtEmpPhone.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[4].ToString();
string param = ds.Tables[strSQL_Table].Rows[0].ItemArray[5].ToString();
Department_dropdown1.Set_dept_value(param);
this.DataBind();

Tuesday, July 12, 2005

SQL Server Query for all values within a month

I have been working on a project at work and I discovered the following works for retrieving dates from SQL Server:

SELECT * FROM view_Employees_Awards WHERE stringDate BETWEEN '2005-06-01' AND
'2005-07-01' ORDER BY Awarded_Date DESC

The following brings back every date from the beginning of 2005-06-01 00:00:00

To

2005-06-01 23:59:59


Monday, July 11, 2005

Moojjoo Blog

Moojjoo Blog

Learning more about C# logic everyday. I needed a dropdown that would display dates in a reverse order so how do you do this.

for (int i = DateTime.Now.Year; i >= 2000; i--)

Simple thanks to the MVP at the forums in MSDN

David Anton
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter

"Moojjoo" wrote:

I am building a dropdown select box for year and want to render the dropdown
in reverse order. Using VB I could use step, but I am unsure how to do this
in C#

Any help would be great.

if (!this.IsPostBack)
{
for (int i = 2000; i <= DateTime.Now.Year; i++)
{
int intSubtractTerm = 0;
ListItem newListItem = new ListItem();
intYear = DateTime.Now.Year;
intSubtractTerm = intYear - i;
intYear = intYear - intSubtractTerm;
newListItem.Value = intYear.ToString();
newListItem.Text = intYear.ToString();
DropDownListYear.Items.Add(newListItem);
}
}

Friday, July 08, 2005

Moojjoo Blog - Using User Controls in Datagrid

And the anwser is:

In the code behind:


str_emp_dept = Convert.ToString(((Department_dropdown)e.Item.FindControl("Department_dropdown2")).Selected_dept_value());

WHOOOOOOHOOOOOOO!!!!!!!!!!!!!!


THE QUESTION IS BELOW... WHEN I GET THE ANSWER I WILL POST IT.

I created an user control (.ascx file) with a DropDownList (DDL) with the
following code behide:

public string Selected_dept_value()
{
string dept_value = dept_dropdown.SelectedValue;
return dept_value;
}

All the values were added via the visual interface.

I have droped this on my .aspx page and everything works fine. When making
additions to my datagrid.

<uc1:department_dropdown id="Department_dropdown1" runat="server"></uc1:department_dropdown>

The problem is when I am editing my datagrid.

Where I have:

<asp:templatecolumn headertext="Department">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Emp_Department") %>
</itemtemplate>
<edititemtemplate>
<uc1:department_dropdown id="Department_dropdown2" runat="server">
</uc1:department_dropdown>
</edititemtemplate>

The DDL displays fine, but I cannot get the values when clicking update:

Here is the error and code behind that it is failing on:

Error: Object reference not set to an instance of an object <-- However I
have the following:

protected Department_dropdown Department_dropdown2;

Code:
str_emp_dept =
((DropDownList)e.Item.FindControl(Department_dropdown2.Selected_dept_value())).SelectedValue;