Sue Hernandez's SharePoint Blog

SharePoint and Related Stuff

Monthly Archives: December 2011

Publish Error in InfoPath 2010 after pressing Cancel

So I went to publish my InfoPath 2010 Form into SharePoint 2010.  I was impatient because it was taking a long time and I needed to change just one more thing.  So I pressed Cancel.

Now I’m getting one of 2 error messages when trying to either Quick Publish or Regular Publish:

“InfoPath cannot save the following form: https://servername/web/subweb/infoPathLib The following file(s) have been blocked by the administrator …”

“InfoPath cannot save the following form:  https://servername/web/subweb/infoPathLib This document library was either renamed or deleted, or network problems are preventing the file from being saved.  If this problem persists, contact your network administrator.”

Well, after trying numerous times to publish and I even changed the InfoPath Form Properties, still no luck.  Sounds pretty dumb, but all I did was to completely close out all instances of InfoPath and my browser (maybe not necessary) and then re-open InfoPath and do a Manual Publish (not a Quick Publish).  I didn’t change any url’s or put in IP addresses or anything like that.

Are you having this trouble?  Does it persist after you have completely closed and re-opened?  Leave me a coment – maybe together we’ll put in a bug report to Microsoft.

~ Sue

Advertisements

Silverlight Gantt Part 5

I have been writing a series about how to create a simple Gantt chart using the latest version of the Silverlight Toolkit.  My links are in my first post, which you can get to from above.

To continue with the topics…

CHANGING THE SERIES BAR’S TOOL TIP

The only thing we really need to do is to find the following XAML:

<ToolTipService.ToolTip>
    
<ContentControl Content=”{TemplateBinding FormattedDependentValue}” />
</ToolTipService.ToolTip>

and change it to:

<ToolTipService.ToolTip>
    
<ContentControl>
         
<StackPanel Orientation=”Horizontal”>
              
<TextBlock Text=”{Binding StartDateDate, StringFormat=\{0:MM\/dd\/yyyy\}}”></TextBlock>
               
<TextBlock Text=” – “></TextBlock>
              
<TextBlock Text=”{Binding EndDateDate, StringFormat=\{0:MM\/dd\/yyyy\}}”></TextBlock>
         
</StackPanel>
    
</ContentControl>
</ToolTipService.ToolTip>

Now here, we’re using data binding from our custom class “DataItem” which I introduced in the last post.  We’re also telling it to format the resultant value in a particular manner, by using the StringFormat extension.  So as long as you’ve been following along, you should have this part completed.  Again, as I’ve said before, we’ll go over the full code for the preparation and binding in probably the last post in this series.

GETTING THE X AXIS TO DISPLAY DATES INSTEAD OF “Days from Min Date”

As I’ve said before, this implementation seems, on the surface, to be a bit messy.  What we’re doing again, is we’re saying, go get me the earliest date (let’s call it 8/1/2011 for sake of argument).  That Date now is going to be represented as the decimal “0” on the X Axis.  Whereas the date 8/25/2011 would be represented as the number “24” on the X Axis – the number of days FROM the minimum date.

Now again, this seems messy but I did try to use the DateTimeAxis object that is provided in the Toolkit.  I couldn’t get it to work using DateTimes.  I posted a forum post and was answered that only Doubles will work as the Dependent Value, not DateTimes.  So I offer that my solution while not pretty, is probably the practical way to do it.

Ok so the first thing to do is to create another Template for the X Axis.  But we also have to make sure we have an XMLNS in our Main Page:

xmlns:layout=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit”

So after we put the XMLNS in the  User Control, we add this new style to the UserControl.Resources section: 

<!– X Axis –>
<Style x:Key=”HorizontalAxisStyle” TargetType=”chartingToolkit:AxisLabel”>
     <Setter Property=”Margin” Value=”0,5,0,0″/>
     <Setter Property=”Template”>
          <Setter.Value>
               <ControlTemplate TargetType=”chartingToolkit:AxisLabel”>
                    <layout:LayoutTransformer>
                         <layout:LayoutTransformer.LayoutTransform>
                              <RotateTransform Angle=”-60″ />
                         </layout:LayoutTransformer.LayoutTransform>
                         <TextBlock 
                              Padding
=”0″ 
                              DataContext
=”{Binding}”
                             
Text=”{Binding Converter={StaticResource AxisDateFormatConverter}, ConverterParameter={StaticResource axisMinDate}}” />
                    </layout:LayoutTransformer>
               </ControlTemplate>
          </Setter.Value>
     </Setter>
</Style>

and of course set this new style in the chart markup

<chartingToolkit:BarSeries.DependentRangeAxis>
     <chartingToolkit:LinearAxis
          Orientation=”X”
         
AxisLabelStyle=”{StaticResource HorizontalAxisStyle}” />
    
</chartingToolkit:BarSeries.DependentRangeAxis>
<chartingToolkit:BarSeries.IndependentAxis>

The Control Template is doing 2 things here:  (1) It is rotating the labels of the X axis by a – 60 degrees; (2) it is printing the text, data bound to the X Axis Label, and using a Converter class with a Static Resource parameter.  Let’s first talk about the AxisDateFormatConverter class.

// Converter for showing the X Axis lables as DateTimes instead of doubles
// Expects the MinDate to be the smallest date of all of the data points
public class AxisDateFormatterIValueConverter
{
     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
          if (parameter != null)
                {
               DateTime minDate = DateTime.MinValue;
               DateTime.TryParse(parameter.ToString(), out minDate); 

               if (minDate != DateTime.MinValue && minDate != DateTime.MaxValue)
                         {
                    DateTime dt = minDate.AddDays((double)value);
                    return dt.ToShortDateString();
                         }
                }
                return value;
        }

         public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    
{
                if (parameter != null)
          
{
                        DateTime minDate = DateTime.MinValue;
              
DateTime.TryParse(parameter.ToString(), out minDate);
             
DateTime endDate = DateTime.MaxValue;
             
DateTime.TryParse(value.ToString(), out endDate); 

                       if (minDate != DateTime.MinValue && endDate != DateTime.MaxValue)
             
{
                               return (endDate.Subtract(minDate)).TotalDays;
             
}
                }

                return value;
     
}
}

This class expects to receive the MinDate value, which is the Earliest StartDateDate of all of your data points.  It takes the number that was passed in, adds those in Days to the MinDate, and returns a string version of that Date.

One of the problems with this, is how to get the MinDate parameter into the function??  Well, I chose to use a Static Resource, made up of a light-weight custom class that simply holds the value for the Min Date:

// For use with a Static Resource, to pass in as a 
// parameter to the Conversion function for the
// X Axis values
public class AxisMinDate
{
        public DateTime Value { get; set; }

     public AxisMinDate()
    
{
        }

        public override string ToString()
    
{
                return Value.ToShortDateString();
    
}
}

Then in the UserControl.Resources section, I add the reference to this custom class, and add the reference to the AxisDateFormatter class as well:

<!– Axis Value Formatter –>
<me:AxisDateFormatter x:Key=”AxisDateFormatConverter” />
<me:AxisMinDate x:Key=”axisMinDate” />

In the code-behind, when setting up the min and max date, at the same time, you set it into your resource:

// Get the Min Date and Max Date for determining the intervals
DateTime maxDate = DateTime.MinValue;
DateTime minDate = DateTime.MaxValue;

foreach (DataItem p in dataPoints)
{
        if(p.EndDateDate > maxDate)
    
{
                maxDate = p.EndDateDate;
        }

        if(p.StartDateDate < minDate)
    
{
                minDate = p.StartDateDate;
        }
}

if (minDate > DateTime.Today)
{
        minDate = DateTime.Today.Subtract(newTimeSpan(10, 0, 0, 0));
}

// Set this date into a resource for use later in styling the X axis labels:
// Instead of numbers, we use dates, calculated as the MinDate plus the
// double Value of the dataPoint (in days).
((AxisMinDate)this.Resources[“axisMinDate”]).Value = minDate;

Next up:  Updating the X Axis Interval such that it only shows about 6-7 points at one time.

MOSS SPSecurity.RunWithElevatedPrivileges Object Reference Not Set

MOSS (SharePoint 2007) SPSecurity.RunWithElevatedPrivileges Object Reference Not Set to an Instance of an Object.

There are a few post out there regarding permissions on the database, and permissions on a local account group; however I just barely found, and wanted to pass on –

If you’re using Visual Studio and you’re running in Debug mode, and you’re either getting the Object Reference on SPSecurity.RunWithElevatedPrivileges or you’re getting a File Not Found error (“Web application at … could not be found”) on new SPSite(webURL), then you might want to check your configuration options.  Are you running in x86 mode and your site is build on 64 bit? 

What I did was I changed my build configuration from x86 to “Any CPU” and that made both exceptions go away.

~Sue

Silverlight Gantt Part 4

In my first post, I started with a teaser of what we’re trying to accomplish; in the second post, I talked about removing the Legend; and in the last post, I talked about putting a “Today” line on the chart.  In that last post, we covered some of the code necessary to data bind the chart, but really didn’t go into deep detail.

ADDING A TEXT LABEL INSIDE OR OUTSIDE OF THE BAR 

So if you look at the picture in the first post, you will notice that there is a Label at the end of the bar that shows the End Date.  That label is by default inside the bar, and has White text.  However, when the bar’s too small, it is displayed outside of the bar, using Black text.

We have to override the Style for the default BarDataPoint style.  Basically you’re telling it how to lay out the bars.  Now I’m going to post the entire style you need to put in your UserControl.Resources section.  Much of it is for stuff I don’t use, like highlighting and selecting; however I’m keeping it in there “just in case”.

So again, put this into your UserControl.Resources section:

<!– BarDataPoint Style and Template –>
<Style x:Key=”BarTemplateStyle1″ TargetType=”chartingToolkit:BarDataPoint”>
    
<Setter Property=”Template”>
         
<Setter.Value>
              
<ControlTemplate x:Name=”BarTemplate” TargetType=”chartingToolkit:BarDataPoint”>
                    
<Grid x:Name=”BarTemplateMainGrid”>
                        
<VisualStateManager.VisualStateGroups>
                             
<VisualStateGroup x:Name=”CommonStates”>
                                  
<VisualStateGroup.Transitions>
                                       
<VisualTransition GeneratedDuration=”0:0:0.1″/>
                                  
</VisualStateGroup.Transitions>
                                  
<VisualState x:Name=”Normal”/>
                                  
<VisualState x:Name=”MouseOver”>
                                       
<Storyboard>
                                            
<DoubleAnimation
                                                  Duration
=”0″ 
                                                  Storyboard.TargetName
=”MouseOverHighlight”
                                                  Storyboard.TargetProperty
=”Opacity”
                                                  To
=”0.6″/>
                                       
</Storyboard>
                                  
</VisualState>
                             
</VisualStateGroup>
                             
<VisualStateGroup x:Name=”SelectionStates”>
                                   <VisualStateGroup.Transitions>
                                       
<VisualTransition GeneratedDuration=”0:0:0.1″/>
                                   </VisualStateGroup.Transitions>
                                  
<VisualState x:Name=”Unselected”/>
                                  
<VisualState x:Name=”Selected”>
                                       
<Storyboard>
                                             <DoubleAnimation
                                                  Duration
=”0″
                                                  Storyboard.TargetName
=”SelectionHighlight”
                                                  Storyboard.TargetProperty
=”Opacity”
                                                  To
 =”0.6″/>
                                       
</Storyboard>
                                  
</VisualState>
                             
</VisualStateGroup>
                              
<VisualStateGroup x:Name=”RevealStates”>
                                  
<VisualStateGroup.Transitions>
                                       
<VisualTransition GeneratedDuration=”0:0:0.5″/>
                                  
</VisualStateGroup.Transitions>
                                  
<VisualState x:Name=”Shown”>
                                       
<Storyboard/>
                                  
</VisualState>
                                  
<VisualState x:Name=”Hidden”>
                                       
<Storyboard/>
                                  
</VisualState>
                             
</VisualStateGroup>
                        
</VisualStateManager.VisualStateGroups>
                        
<ToolTipService.ToolTip>
                              <!– ######### THIS WILL BE CHANGED LATER –>
                              
<ContentControl Content=”{TemplateBinding FormattedDependentValue}”/>
                         </ToolTipService.ToolTip>
                        
<Rectangle x:Name=”SelectionHighlight”
                              Opacity
=”0″ 
                              Fill
=”Red” 
                              Grid.RowSpan
=”2″
                              Grid.ColumnSpan
=”3″
                              Margin
=”1.332,0,-1.332,0″/>
                        
<Rectangle x:Name=”MouseOverHighlight”
                              Opacity
=”0″
                              Fill
=”White”
                              Grid.RowSpan
=”2″ 
                              Grid.ColumnSpan
=”3″/>
                        
<Grid x:Name=”GanttDataPointBody”>
                             
<Rectangle Fill=”#FF284B70″/>
                             
<Path Stretch=”Fill” 
                                   Data
=”F1 M16.9979,-38.6618 L304.96201,-38.6618 L295.85101,-12.98486 C293.37601,-10.55966 290.95508,-6.5848103 288.04709,-5.3772006 C285.1391,-4.1696005 266.16092,-4.4174142 262.82092,-4.4273643 L60.699768,-5.1715899 C56.235268,-5.1848698 37.786591,-5.2874784 34.107491,-6.7409983 C30.428286,-8.1945286 28.571583,-13.514527 25.677784,-16.408327 L16.9979,-38.6618 z”
                                   Height
=”10.008″
                                   VerticalAlignment
=”Top”
                                   d
:LayoutOverrides=”Height, GridBox”>
                                  
<Path.Fill>
                                       
<LinearGradientBrush StartPoint=”0.506944,-0.479586″ EndPoint=”0.506944,0.980026″>
                                            
<GradientStop Color=”#00000000″ Offset=”0″/>
                                             
<GradientStop Color=”#FFB9D6F7″ Offset=”0.496″/>
                                            
<GradientStop Color=”#FF284B70″ Offset=”1″/>
                                       
</LinearGradientBrush>
                                  
</Path.Fill>
                              
</Path>
                             
<!– ######### ADDITION HERE –>
                             
<TextBlock
                                  
x:Name=”DataPointLabel”
                                  
Foreground=”{Binding Foreground}”
                                  
Margin=”{Binding TextLabelMargin}”
                                  
VerticalAlignment=”Center”
                                  
TextAlignment=”Right”
                                   
Text=”{Binding FormattedValue}”>
                              </
TextBlock>
                             
<!– ######### END ADDITION –>
                         
</Grid>
                    
</Grid>
               
</ControlTemplate>
          
</Setter.Value>
     
</Setter>
</Style>

And now you need to update your BarSeries element inside your Chart to point to the new style.

<chartingToolkit:BarSeries
    
x:Name=”BarSeries1″
    
DataPointStyle=”{StaticResource BarTemplateStyle1}”>

 You will notice that in the textblock we have some binding going on

 <!– ######### ADDITION HERE –>
<TextBlock
    
x:Name=”DataPointLabel”
    
Foreground=”{Binding Foreground}”
    
Margin=”{Binding TextLabelMargin}”
    
VerticalAlignment=”Center”
    
TextAlignment=”Right”
    
Text=”{Binding FormattedValue}”>
</
TextBlock>
<!– ######### END ADDITION –>

Well what we’ve done here, is that the Bar Series will be Data Bound to a Custom Class that we create to hold the data.  Let’s take a look at that custom class:

public class DataItem
{
         publicstring Key { get; set; }
    
public DateTime MinDate { get; set; }
    
public double StartDate { get; set; }
    
public double EndDate { get; set; }
    
public string TextLabelMargin { get; set; }
    
public string Foreground { get; set; }

     public
DateTime StartDateDate { get; set; }
    
public DateTime EndDateDate { get; set; }

     public string FormattedValue
    
{
                   get
          
{
                          returnstring.Format(“{0:MM/dd/yyyy}”, EndDateDate);
           
}
        }

        public void SetDateDoubles()
    
{
                if (MinDate != DateTime.MinValue)
         
{
                         StartDate = (StartDateDate.Subtract(MinDate)).Days;
                         EndDate = (EndDateDate.Subtract(MinDate)).Days;
                 }
         }

         public DataI tem(string _key, DateTime _start, DateTime _end, string _margin, string _foreground)
    
{
               Key = _key;
               StartDateDate = _start;
               EndDateDate = _end;
               Foreground = _foreground;
        }

        public DataItem()
    
{
         }

We basically populate it with the Start and End dates, and provide it a “Minimum Date” to calculate the number of days it’s been since the first date on the graph we want to use.  So for example if the MinDate was 10/1/2011 and the StartDateDate was 10/11/2011 then the StartDate value would be 10.  That’s how we’re using Doubles to plot the values on the X axis.

When we go through setting up our values into this custom class, we use the default values of “0,0,10,0” for the Margin, which puts a 10 pixel margin on the right (the text box is right-aligned).  We start with the default Foreground color of “White”.

foreach (ListItem item in spItems)
{
         try
    
{
                 // Populate the DataItem collection (dataPoints)
          
//…

          DataItem point = new DataItem(key, StartDate, EndDate, “0,0,10,0”, “White”);

                dataPoints.Add(point);
        }
        catch (Exception ex1)
    
{
                MessageBox.Show(ex1.ToString());
    
}
}

Then we calculate the Minimum and Maximum dates, so that we can set those values in the data points.  Yea, it’s a twice go-round of the data points, but it was either that or make 2 Server calls.

// Get the Min Date and Max Date for determining the intervals
DateTime maxDate = DateTime.MinValue;
DateTime minDate = DateTime.MaxValue;

foreach (DataItem p in dataPoints)
{
        if(p.EndDateDate > maxDate)
    
{
                maxDate = p.EndDateDate;
        }

        if(p.StartDateDate < minDate)
    
{
               minDate = p.StartDateDate;
        }
}

if (minDate > DateTime.Today)
{
        minDate =DateTime.Today.Subtract(newTimeSpan(10, 0, 0, 0));
}

// Total number of days from start to finish
double max = (maxDate.Subtract(minDate)).Days;

if(max == 0)
{
        mcChart.Title =“Sample Data”;
    
return;
}

foreach (DataItem p in dataPoints)
{
        p.MinDate = minDate;
        p.SetDateDoubles(); 

     // This is an approximation, as the actual X Axis points 
    
// have not yet been set
     
int daysWidth = (p.EndDateDate.Subtract(p.StartDateDate)).Days;

     if(daysWidth < 100)
    
{
                p.TextLabelMargin =“-75,0,-75,0”;
         
p.Foreground =“Black”;
    
}
}

By setting a negative Right margin here, you effectively bring it outside and to the right of the end of the bar.  I noticed I also had to change the left margin too, or the date was getting cut off for some reason.

Next you data bind, but again, we’ll be talking more in depth about that in a later post, probably toward the end of the series.

Next time, Changing the ToolTip for the bar.  See you next time!