Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>there is a way to change the name of the file that we downloaded to our "~Server/Userfolder"(as an example)..</p> <p>i was really thinking on renaming file before the .SaveAs command, which is gonna be like:</p> <pre><code>if (Request.Files != null) { var getmyfile = Request.Files["some_photo"]; try { if (getmyfile.FileName != "" &amp;&amp; getmyfile.FileName != null &amp;&amp; getmyfile.ContentLength &gt; 0) { ///Create Useruploads path. var path = Server.MapPath("~/Useruploads" + "\\"); ///Get file info that we gonna upload to server.. FileInfo TheFile = new FileInfo(path + Path.GetFileName(getmyfile.FileName)); ///Note: i used Path.GetFileName(getmyfile.FileName) code cause getmyfile.FileName gives full path of that file.. if (TheFile.Exists) { ///Seperate file name and extention.. var fname = Path.GetFileNameWithoutExtension(TheFile.Name); var ext = TheFile.Extension; var path2 = path + fname; ///As long as we got file names, same as in server.. while(new FileInfo(path2+ext).Exists) { ///Add "-img" to its name.. path2 = path2 + "-img"; } FileInfo ccc = new FileInfo(path2 + ext); string f_art = ccc.Name.Replace(" ", "");///Clean space.. (Optional) getmyfile.SaveAs(f_art); somedb.some_photo = Path.GetFileName(f_art); ///Its not fart its file art lol! } else ///if file is not exist in our server.. { var path3 = (path + Path.GetFileName(getmyfile.FileName)); FileInfo ccc = new FileInfo(path3); string f_art = ccc.Name.Replace(" ", ""); getmyfile.SaveAs(f_art); some.some_photo = Path.GetFileName(f_art); } } } catch(FileNotFoundException ex) { form.Set("lblStatus",ex.Message); } catch (Exception ex) { form.Set("lblStatus", ex.Message); } db.somedbs.InsertOnSubmit(somedb); db.SubmitChanges(); return RedirectToAction("Index"); } </code></pre> <p>(Optional) Also u can use :</p> <pre><code>var f_art = System.Text.RegularExpressions.Regex.Replace(Path.GetFileNameWithoutExtension(TheFile.Name), "[^a-zA-Z]", ""); </code></pre> <p>instead of using .Replace(" ",""); but at this it just cleans spaced areas and if u use the code up there its gonna clean everything except A to Z , a to z characters which means no numbers will be applied to that name nor space or other characters which are not between A and Z..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload