Upload image

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
8/11/2011 8:32:57 AM
Gravatar
Total Posts 4

Upload image

Hi,

I am trying to upload image to server, and write path to my mssql table. But I need to create folder  with user id in that table. (my user id=1, i want to add image.jpg file to Folder/Images/1 and save to table Folder/Images/1/image.jpg). that is the best way to do it? 

Regards

8/14/2011 4:31:57 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: Upload image

string fileName =yourFileName;
                                               string SaveFolder = Server.MapPath("//") + "Data\\Sites\\" + siteSettings.SiteId + "\\userfiles\\" + userid + "\\";

                            if (!Directory.Exists(SaveFolder))
                                Directory.CreateDirectory(SaveFolder);

                            // this is a new projectgalleryImage instance, make sure we don't use the same file name as any other instance
                            string newFileName = fileName;
                            int i = 1;
                            while (File.Exists(SaveFolder + newFileName))
                            {
                                newFileName = i.ToInvariantString() + newFileName;
                                i += 1;
                            }
                            fileName = newFileName;
                        try
                        {
                            txtUpload.PostedFile.SaveAs(Server.MapPath("//") + "Data\\Sites\\" + siteSettings.SiteId + "\\userfiles\\" + userid + "\\" + fileName);

                        }
                        catch (Exception ex)
                        {
                            lblUploadError.Text = "ERROR: " + ex.Message.ToString();
                        }

 

something like this will help

8/14/2011 12:02:58 PM
Gravatar
Total Posts 245
mojoPortal Community Expert

Re: Upload image

The mojo way.

First add a reference to Brettle.Web.NeatUpload in your feature project.

Then, to use the mojoPortal "fileupload" Brettle.Web.NeatUpload you could copy/modify code from...

In the mojoPortal source code, go the the project folder WebStore.UI.  In the Webstore folder there is a file called AdminProductEdit.aspx with an associated C# file.

Most of what you need is in those 2 files.

Copy the aspx section add <asp:Panel ID="pnlFileUpload"
to your aspx page.

Copy the C# section add private void btnUpload_Click(object sender, EventArgs e)
to your C# page. Replace or remove product specific code with your feature code.

You are almost done...

Also...
In your page LoadSettings() method include something like...
upLoadPath = Server.MapPath("~/Data/Sites/" + siteSettings.SiteId.ToInvariantString()
                + "/yourfeaturename/");

if (!Directory.Exists(upLoadPath))
{
   Directory.CreateDirectory(upLoadPath);
}

 

Tip - To make unique file names I use something like this
var dateString = string.Format("{0:yyyy-MM-dd_hh-mm-ss}", DateTime.Now);
string fileName = _sUser + "_yourfeaturename_" + dateString;

Hope this helps

Rick Hubka

 

 

8/15/2011 3:10:15 AM
Gravatar
Total Posts 192

Re: Upload image

Great, I was going to ask about this. thanks.

You must sign in to post in the forums. This thread is closed to new posts.