I can´t get rid of the whitespaces in a string.. Here is my code
if (!string.IsNullOrEmpty(b))
{
Encoding encode = Encoding.Unicode;
byte[] bytes = Convert.FromBase64String(b);
MemoryStream memoryStream = new MemoryStream(bytes);
BinaryReader binary = new BinaryReader(memoryStream);
int fileSize = (int) binary.ReadUInt32();
int attachmentNameLength = (int) binary.ReadUInt32()*2;
byte[] fileNameBytes = binary.ReadBytes(attachmentNameLength);
string name = encode.GetString(fileNameBytes, 0, attachmentNameLength - 2);
byte[] decodeFile = binary.ReadBytes(fileSize);
name = ConvertSpecialCharacters(name);
item.Attachments.Add(name, decodeFile);
item.UpdateOverwriteVersion();
}
private string ConvertSpecialCharacters(string stringToConvert)
{
stringToConvert = stringToConvert.Replace("~", string.Empty);
stringToConvert = stringToConvert.Replace("#", string.Empty);
stringToConvert = stringToConvert.Replace("%", string.Empty);
stringToConvert = stringToConvert.Replace("&", string.Empty);
stringToConvert = stringToConvert.Replace("*", string.Empty);
stringToConvert = stringToConvert.Replace("{", string.Empty);
stringToConvert = stringToConvert.Replace("}", string.Empty);
stringToConvert = stringToConvert.Replace("\\", string.Empty);
stringToConvert = stringToConvert.Replace(":", string.Empty);
stringToConvert = stringToConvert.Replace("<", string.Empty);
stringToConvert = stringToConvert.Replace(">", string.Empty);
stringToConvert = stringToConvert.Replace("?", string.Empty);
stringToConvert = stringToConvert.Replace("/", string.Empty);
stringToConvert = stringToConvert.Replace("|", string.Empty);
stringToConvert = stringToConvert.Replace("\"", string.Empty);
stringToConvert = stringToConvert.Trim();
return stringToConvert;
}
Please help!