Trim Attachment Filename - InfoPath Dev
in

InfoPath Dev

Trim Attachment Filename

Last post 11-06-2014 10:56 AM by Ravik. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 10-29-2014 09:30 AM

    • Ravik
    • Top 500 Contributor
      Male
    • Joined on 01-25-2013
    • Aberdeen(Scotland)
    • Posts 33

    Trim Attachment Filename

    Hi All, Is there a way to restrict or trim the attachment file if it exceeds more than 100 or 128 character? Regards, Ravi
  • 11-03-2014 01:55 AM In reply to

    Re: Trim Attachment Filename

    Hi Ravik,

    Please refer to Hilary's post from this thread. Alternatively, you can also use qRules to validate or even overwrite the file name with a desired value (based from other fields, current user, etc.) without writing code. Hope this helps.

    Don Stephen Lambatin / Support Engineer
    Qdabra Software
  • 11-06-2014 10:56 AM In reply to

    • Ravik
    • Top 500 Contributor
      Male
    • Joined on 01-25-2013
    • Aberdeen(Scotland)
    • Posts 33

    Re: Trim Attachment Filename

    Hi Dan, Sorry for the late reply. I do have Decoding and Encoding for my file attachments. What i was trying to do was, when the user tries to upload a file with a file name more than 128 characters. I wanted to trim the file name before it gets pushed to the library. Please see my code below private string CleanFileName(string filename) { string invalidCharacters = "[\\~#%&*{}/:<>?|\"-]"; Regex invalidCharactersRegex = new Regex(invalidCharacters); filename = Regex.Replace(invalidCharactersRegex.Replace(filename, ""), @"\s+", ""); if (filename.Length > 128) { filename = string.Format("{0}.{1}",Path.GetFileNameWithoutExtension(filename).Substring(0, 128), Path.GetExtension(filename)); } return filename; } Not sure what i am doing wrong here. Look forward to hear from you. Regards, Ravi
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.