jump to navigation

Change Background of Combobox using a Trigger if IsEditable November 5, 2008

Posted by spunkyvt in Programming, WPF.
Tags: , ,
add a comment

After many frustrations of googling and coding I finally found how to change the background of a combobox when triggering on IsFocused and the combobox is editable. When the combo is in edit mode it displays a regular textbox for it’s edit portion.  In the Style trigger section use a data trigger and bind to the element PART_EditableTextBox.

<Style.Triggers>

<DataTrigger Binding=”{Binding ElementName=PART_EditableTextBox,Path=IsFocused}” Value=”True”>
<Setter Property=”Background” Value=”Yellow”/>
</DataTrigger>
</Style.Triggers>

Change location secondary DataSource for InfoPath browser-based May 13, 2008

Posted by spunkyvt in Programming, Sharepoint.
Tags: , , ,
add a comment

The title is a little misleading, because we are not actually changing the datasource.

In the FormEvents_Loading method put this code

String titleName = e.InputParameters["XmlLocation"].Substring(e.InputParameters["XmlLocation"].LastIndexOf(“/”)+1);

using (SPSite site = new SPSite(_baseURL))
{

using (SPWeb web = site.OpenWeb())
{
SPList ls = web.Lists[_FormName];

SPQuery query = new SPQuery();
query.Query = “<Where><Eq><FieldRef Name=’Title’/><Value Type=’Text’>” + titleName + “</Value></Eq></Where>”;

SPListItemCollection its = ls.GetItems(query);

string h = its[0]["ColumnName"].ToString() ;

}
}

Dynamic Submit with Infopath browser May 8, 2008

Posted by spunkyvt in Programming, Sharepoint.
Tags: ,
add a comment

Ever need to develop an infopath form, but deploy it to another machine and not go through the hassel of Microsofts tool or bringing each form up in infopath and changing location.

First make a data connection and call it ChangeSubmit

Place a button on the form.

In the clicked event from code behind put this code

FileSubmitConnection submit = (FileSubmitConnection)this.DataConnections["ChangeSubmit"];

submit.FolderUrl = “pathtoyourformlibrary”;

submit.Execute();

You can make this much more dynamic, but I just wanted to show the simple version on how to switch this.

Dynamically Add to Drop-Down in Infopath using a Web Service May 7, 2008

Posted by spunkyvt in Programming, Sharepoint.
Tags: , , ,
add a comment

OK. After banging my head about for hours now, I have finally found a solution. This is going to use the permissions built into Sharepoint. It will list out all the groups that have permissions to a form library.

First you need to make an xml file.

Create an xml file with this info in it. Name it Permiss.xml.

Drag a drop-down box onto the infopath form. Click on DataConnections under tools. Click the add button. Create a new connection and set it to Receive Data. Click the Next and choose XML Document. Browse to the file location and choose the Permiss.xml file. Cick next and Make sure that Automatically retrieve data when form is opened is checked.

Right Click on the Drop-Down List Box properties. Click on the Look up values from an external data source. In the Data source drop down pick permiss. Click on button beside Entries and choose the permissions node. Click OK. Next click button beside Value and choose MemberID. Click OK. Click the button beside Display name and choose GroupName. Finally all done there.

Now onto the code behind.

Add a web reference to the http://localhost/_vti_bin/permissions.asmx

Call it permission.

In the FormEvents_loading method add this code

permissions.Permissions perm = new GFill.permissions.Permissions();

perm.Credentials = System.Net.CredentialCache.DefaultCredentials;

String FormName = “youLibrary”

XmlNode nod = perm.GetPermissionCollection(FormName, “List”);

XPathNavigator sitepermiss = DataSources["permiss"].CreateNavigator() ;
XmlNamespaceManager umanager = new XmlNamespaceManager(sitepermiss.NameTable);
umanager.AddNamespace(“ns1″, “http://schemas.microsoft.com/sharepoint/soap/directory/”);

XPathNavigator f1 = sitepermiss.SelectSingleNode(“//ns1:GetPermissionCollection/ns1:Permissions”, umanager);

XPathNavigator g = nod.CreateNavigator().SelectSingleNode(“//ns1:Permissions”, umanager);
f1.ReplaceSelf(g);

If all goes well this is all you should need in order to dynamically fill those drop-downs. I have to vent for a second. This is way harder than it should be. Something this simple and trivial should not have been this complicated to implement. Kudos Microsoft. You win the Rube Goldberg award for the day. I hope this will save someone else numerous hours.

Activity in WorkFlow with Sharepoint May 6, 2008

Posted by spunkyvt in Programming, Sharepoint.
Tags: , , ,
4 comments

I am going to show you how to add an activity to a workflow, which will take a sharepoint list item and convert it to a dataset.

I will be using vs 2005 with workflow developer starter kit for windows sharepoint services V3 installed

Start a new project and under workflow pick the Workflow Activity Library

Add the Microsoft.SharePoint.dll

In order to use properties you have to use a special type of property called a DependencyProperty. These are used when you define the workflow parameters.

Add these DependencyProperties to class.

public static DependencyProperty _ContextProperty = DependencyProperty.Register(“_Context”, typeof(WorkflowContext), typeof(Activity1));
public static DependencyProperty ListItemProperty = DependencyProperty.Register(“ListItem”, typeof(int), typeof(Activity1));
public static DependencyProperty FileSavePathProperty = DependencyProperty.Register(“FileSavePath”, typeof(string), typeof(Activity1));
public static DependencyProperty ListIdProperty = DependencyProperty.Register(“ListId”, typeof(string), typeof(Activity1));

[Description("Cross-Site Actions")]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string FileSavePath
{
get
{
return ((string)(base.GetValue(Activity1.FileSavePathProperty)));
}
set
{
base.SetValue(Activity1.FileSavePathProperty, value);
}
}

[Description("Context")]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public WorkflowContext _Context
{
get
{
return ((WorkflowContext)(base.GetValue(Activity1._ContextProperty)));
}
set
{
base.SetValue(Activity1._ContextProperty, value);
}
}

[Category("Cross-Site Actions"), Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
public string ListId
{
get
{
return ((string)
(base.GetValue(Activity1.ListIdProperty )));
}
set
{
base.SetValue(Activity1.ListIdProperty, value);
}
}

[Category("Cross-Site Actions"), Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int ListItem
{
get
{
return ((int)
(base.GetValue(Activity1.ListItemProperty)));
}
set
{
base.SetValue(Activity1.ListItemProperty, value);
}
}

In the Execute method as this

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
try
{
using (SPSite mySite = new SPSite(this._Context.Web.Site.ID))
{
using (SPWeb web = mySite.AllWebs[this._Context.Web.ID])
{
Guid myG = new Guid(this.ListId);
SPList list = web.Lists[myG];

SPListItem li = list.Items[this.ListItem-1];

DataTable dt = new DataTable(“Sharepoint”);

dt.Rows.Add(dt.NewRow());

foreach (SPField var in li.Fields)
{
string colName = var.InternalName;
DataColumn dc = new DataColumn(colName);
dt.Columns.Add(dc);
DataRow dr = dt.Rows[0];
dr[dc] = li[var.InternalName];
}
if (Directory.Exists(this.FileSavePath))
{
string dir;
if (this.FileSavePath.EndsWith(“\\”))
dir = this.FileSavePath;
else
dir = this.FileSavePath + “\\”;
dt.WriteXml(dir + li.UniqueId.ToString()+ “.xml” );
}
else
{
throw new Exception(“Missing Directory”);
}
}
}
}
catch (Exception)
{

throw;
}
return ActivityExecutionStatus.Closed;

}

Now sign the assembly and put the compiled Dll int he GAC

This is at as far a code is concerned. Now to add it to sharepoint.

Next go the web.config file for your sharepoint site.

You add an entry to the <System.Workflow.ComponentModel.WorkflowCompiler> section.

similar to this

<authorizedType Assembly=ActivityLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8fd4b4c3a190a3c6 Namespace=ActivityLibrary1 TypeName=* Authorized=True />

The publickeytoken comes from when you installed it in the GAC.

Next find the .ACTIONS file in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\Workflow.

Add this xml node to the file between the <Actions></Actions> section. There might already be others there so just put it at the end of the last one. Be sure that publickeytoken matches the one you have in the GAC.

<Action
Name=”Write List item to the folder”
ClassName=”ActivityLibrary1.Activity1″
Assembly=”ActivityLibrary1, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=2d6bcfd54854da8d”
AppliesTo=”all”
Category=”Extras”>
<RuleDesigner Sentence=”Context %1 SavePath %2″>
<FieldBind
Field=”ListId,ListItem”
Text=”this”
Id=”1″
DesignerType=”ChooseDoclibItem” />
<FieldBind
Field=”FileSavePath”
Text=”Path”
Id=”2″
DesignerType=”Text” />
</RuleDesigner>
<Parameters>
<Parameter
Name=”__Context”
Type=”Microsoft.SharePoint.WorkflowActions.WorkflowContext,
Microsoft.SharePoint.WorkflowActions”
Direction=”In”/>
<Parameter
Name=”ListId”
Type=”System.String, mscorlib”
Direction=”In” />
<Parameter
Name=”ListItem”
Type=”System.Int32, mscorlib”
Direction=”In” />
<Parameter
Name=”FileSavePath”
Type=”System.String, mscorlib”
Direction=”In” />
</Parameters>
</Action>

You might need an iisreset here. So at Start-Run just type iisreset.

To make life easy for you, use the Sharepoint Designer.

Point to you sharepoint site and under new add a new Workflow.

Give the workflow a name and pick wich list you want to attach it to and the start options you want for your workflow

Click next

Under actions go to more actions. In the list you should find the “Write List Item to the Folder”.

Click the add

After this click the blue “this” and use current item. Then click the blue “Path” and type in the path to the folder where you will be saving you list items.

Your workflow is now installed and ready to go. Give it a GO!

VLC and C# April 21, 2008

Posted by spunkyvt in Programming.
Tags: , , ,
1 comment so far

I have found a cool way to embed media (dvd,mp3,mpeg,avi) into your apps.

You will need to use VLC The greatest players out there.

Also you will need to compile the library here

Build the library and add reference in your project

Place a picturebox or panel on the form and a button.

Add this code to form

VLanControl.VlcUserControl vlc = new VLanControl.VlcUserControl();

On the button click

vlc.Width = pictureBox1.Width;
vlc.Height = pictureBox1.Height;
vlc.Parent = pictureBox1;
vlc.CreateControl();
pictureBox1.Controls.Add(vlc);

vlc.AddAndPlay(@”C:\media”,”");

That is it!!!!

There are some options that you can set..but the act a little funny

Let’s say you wanted to add a marquee to the video.

Instead of using the vlc.AddAndPlay use this

vlc.ClearPlayList();
string[] opts = {“sub-filter=marq” };
vlc.AddToPlayList(@”C:\media”, “”, opts);

vlc.SetConfigVariable(“marq-position”, “0″);
vlc.SetConfigVariable(“marq-marquee”, “MY Marquee”);
vlc.SetConfigVariable(“volume”, “0″);

vlc.Play();

What is strange about this?? well if you use the SetConfigVariable to set the sub-filter=marq this will fail also if you put the setConfigVariable commands in the opts they will fail.  This was the only way i could get the desired behavior.

Alright!!!  What about skipping and moving and all that jazz.

OK!!! OK!! Hold on.

Put a timer and track bar on your form.

Put this in your button click also

while (vlc.IsPlaying == false)
{
Application.DoEvents();
}

trackBar1.Maximum = vlc.Length;
trackBar1.Minimum = 0;
timer1.Enabled = true;
timer1.Start();

You will need the while loop to make sure that the trackbar gets the right information from your vlc instance.

On the Tick event of the timer

try
{
if (vlc.IsPlaying)
trackBar1.Value = vlc.Time;
}
catch (Exception ex)
{
}

And in the TrackBar_Scroll Event

try
{
if (trackBar1.Value > vlc.Time)
{
vlc.Shuttle((trackBar1.Value – vlc.Time));
}
else
{
vlc.Shuttle(-(vlc.Time – trackBar1.Value));
}
}
catch
{
}

That is all I have for now.  Enjoy!

PowerPoint in it’s own window or Form w/o the annoying Flash April 16, 2008

Posted by spunkyvt in PowerPoint, Programming.
Tags: , , ,
2 comments

After much searching and digging. I have finally found a solution. First you must download the dsoFramer active x control from microsoft. After that we can code.

Place the Framer on the Form.

Add a reference to the InteropServices. ie.

using System.Runtime.InteropServices;

Add this DllImport

[DllImport("user32.dll", EntryPoint = "LockWindowUpdate", SetLastError = true,
ExactSpelling = true, CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
private static extern long LockWindow(long Handle);

Add a button to the Form

and put this code in button click

Framer.FrameHookPolicy = DSOFramer.dsoFrameHookPolicy.dsoSetOnFirstOpen;

LockWindow(Framer.Handle.ToInt32());
Framer.Open(@”c:\Presentation1.ppt”);

Framer.Activate();
SendKeys.Send(“{F5}”);
Framer.BackColor = Color.Black;
LockWindow(IntPtr.Zero.ToInt32());

You now have a functioning slideshow inside of your form.

If you need control over the slideshow?????????

Well add a reference to you favorite Powerpoint Dll

add using PowerPoint = Microsoft.Office.Interop.PowerPoint;

Define a variable

PowerPoint.Presentation pres;

In the button click add this

pres = (PowerPoint.Presentation)Framer.ActiveDocument;

It’s crazy but you would have to pay 999 from EDraw Office Viewer Component for this same functionality.

MEOUCH!!!!!!!