Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions DocX/DocX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3275,13 +3275,17 @@ select e.Attribute(r + "id").Value
}
else
{
// Set the length of this stream to 0
stream.SetLength(0);
if (stream.CanSeek) // 2013-05-25: Check if stream can be seeked to support System.Web.HttpResponseStream
{
// Set the length of this stream to 0
stream.SetLength(0);

// Write to the beginning of the stream
stream.Position = 0;
// Write to the beginning of the stream
stream.Position = 0;
}

memoryStream.WriteTo(stream);
memoryStream.Flush();
}
#endregion
}
Expand Down Expand Up @@ -3608,13 +3612,14 @@ select int.Parse(d.Attribute(XName.Get("pid")).Value)
pid = pids.Max();

// Check if a custom property already exists with this name
// 2013-05-25: IgnoreCase while searching for custom property as it would produce a currupted docx.
var customProperty =
(
from d in customPropDoc.Descendants()
where (d.Name.LocalName == "property") && (d.Attribute(XName.Get("name")).Value == cp.Name)
where (d.Name.LocalName == "property") && (d.Attribute(XName.Get("name")).Value.Equals(cp.Name,StringComparison.InvariantCultureIgnoreCase))
select d
).SingleOrDefault();

// If a custom property with this name already exists remove it.
if (customProperty != null)
customProperty.Remove();
Expand All @@ -3628,7 +3633,7 @@ select d
new XAttribute("fmtid", "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"),
new XAttribute("pid", pid + 1),
new XAttribute("name", cp.Name),
new XElement(customVTypesSchema + cp.Type, cp.Value)
new XElement(customVTypesSchema + cp.Type, cp.Value??"")
)
);

Expand All @@ -3637,7 +3642,7 @@ select d
customPropDoc.Save(tw, SaveOptions.None);

// Refresh all fields in this document which display this custom property.
UpdateCustomPropertyValue(this, cp.Name, cp.Value.ToString());
UpdateCustomPropertyValue(this, cp.Name, (cp.Value ?? "").ToString());
}

/// <summary>
Expand Down