asp.net - Get the next file name to upload -
i have following c# code (which uploading files server)
for (int = 0; < request.files.count-1; i++) { if (request.contentlength != 0) { int size = request.files[i].contentlength / 1024; if (size <= 512) { string localfile = request.files[i].filename; int dot = localfile.lastindexof('.'); string filetype = localfile.substring(dot + 1); if (filetype == "gif" || filetype == "jpg" || filetype == "png" || filetype == "gif" || filetype == "jpg" || filetype == "png") { int lastindex = localfile.lastindexof(@"\") + 1; string file = localfile.substring(lastindex, localfile.length - lastindex); string path = server.mappath(" ../images/tracks") + "..\\" + file; request.files[i].saveas(path); if (i != request.files.count - 1) imagelist += string.format("images/tracks/{0}|", file); else { imagelist += string.format("images/tracks/{0}", file); } } } else { response.write("the file big !"); } } else { response.write("unknown error !"); } }
the problem there more 1 file upload field.
i want creat condition, check if there file after file[i] (chack if file[i+1] empty) if yes program code: imagelist += string.format("images/tracks/{0}", file);
else: imagelist += string.format("images/tracks/{0}|", file);
my question how condition should like?
whish help, thanks!
just remove condition(if) , add strings ending character. @ end of loop, can remove last character, if "|".
on code:
for (int = 0; < request.files.count-1; i++) { if (request.contentlength != 0) { int size = request.files[i].contentlength / 1024; if (size <= 512) { string localfile = request.files[i].filename; int dot = localfile.lastindexof('.'); string filetype = localfile.substring(dot + 1); if (filetype == "gif" || filetype == "jpg" || filetype == "png" || filetype == "gif" || filetype == "jpg" || filetype == "png") { int lastindex = localfile.lastindexof(@"\") + 1; string file = localfile.substring(lastindex, localfile.length - lastindex); string path = server.mappath(" ../images/tracks") + "..\\" + file; request.files[i].saveas(path); //if (i != request.files.count - 1) imagelist += string.format("images/tracks/{0}|", file); //else { imagelist += string.format("images/tracks/{0}", file); } } } else { response.write("the file big !"); } } else { response.write("unknown error !"); } } //remove last character if (imagelist.endswith("|")) imagelist = imagelist.remove(imagelist.length - 1, 1); }
Comments
Post a Comment