Click here to Skip to main content
15,916,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to create MediaObjectUrl object dynamically to upload image files on my blog.
The images's path has sequence so I want to make the url using for loop.
Here is my source code I have tired like this below but it doesn't work.
Can anybody fix my bad source code
Thank you in advance.

C#
for (int i = 1; i <= 3; i++)
               {
                   MediaObjectUrl[] MO_url= mw.newMediaObject(blogid, username, password, mw.CreateMediaObject(i.ToString()));
               }
               Post post = new Post();
               //post.categories = new string[] { "Test Posts" };
               post.title = "Test Title"";
               //내용 작성
               post.description =  "<img src =" + MO_url[1].url.ToString() + 
                                  "<br>" +
                                  "<img src =" +MO_url[2].url.ToString()+">"+
                             
                                   "<br>" +
                                   "<img src =" + MO_url[3].url.ToString() + ">" +



in MetaWebBlogapi.cs
C#
public struct MediaObjectUrl
  {
      public string url;
  }

  public struct MediaObject
  {
      public string name;
      public string type;
      public byte[] bits;
  }


  public class MetaWeblogApi : XmlRpcClientProtocol
  {
      public MetaWeblogApi(String uri)
      {
          base.Url = uri;
      }
      // posting
      [XmlRpcMethod("metaWeblog.newPost")]
      public string newPost(string BlogID, string ID, string Password, Post Content, bool Publish)
      {
          return (string)this.Invoke("newPost", new object[] { BlogID, ID, Password, Content, Publish });
      }

      // file upload
      [XmlRpcMethod("metaWeblog.newMediaObject")]
      public MediaObjectUrl newMediaObject(string BlogID, string ID, string Password, MediaObject MediaObject)
      {
          return (MediaObjectUrl)this.Invoke("newMediaObject", new object[] { BlogID, ID, Password, MediaObject });
      }

      
      public MediaObject CreateMediaObject(string FilePath)
      {

          if (File.Exists(FilePath) == false) throw new Exception("No file exist");

          MediaObject MediaObject = new MediaObject();
          MediaObject.name = Path.GetFileName(FilePath);
          MediaObject.bits = File.ReadAllBytes(FilePath);


          string Extention = Path.GetExtension(FilePath);
          MediaObject.type = "application/" + Extention;  

          
          RegistryKey Key = Registry.ClassesRoot.OpenSubKey(Extention);
          if (Key != null)
          {
              string Result = (string)Key.GetValue("Content Type");
              if (Result != null) MediaObject.type = Result;
          }

          return MediaObject;

      }
  }


What I have tried:

..........................................
Posted
Updated 20-May-16 5:03am
v4
Comments
ZurdoDev 20-May-16 10:35am    
What doesn't work about it?
hapiten 20-May-16 10:41am    
It is about MetaWebblogapi
ZurdoDev 20-May-16 11:01am    
OK. But you said "it doesn't work." We need a lot more info. Imagine calling your mechanic and telling them "my car doesn't work." That doesn't tell us enough.
hapiten 20-May-16 11:58am    
Thank you
I didn't know that how to make array for object..
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"C:\carku\img\" + OnCarNo_blog);
int count = dir.GetFiles().Length;
// MediaObjectUrl MO_url = mw.newMediaObject(blogid, username, password, mw.CreateMediaObject("c:\\test.jpg"));
MediaObjectUrl[] MO_url = new MediaObjectUrl[count];

for (int i = 0; i < count; i++)
{
MO_url[i]= mw.newMediaObject(blogid, username, password, mw.CreateMediaObject(img_file_path+(i+1).ToString()+"_2.jpg"));
}
I made it now thank you anyway

1 solution

That first block of code does not look right. Try:
C#
MediaObjectUrl[] MO_url;
for (int i = 1; i <= 3; i++)
{
    MO_url[i] = mw.newMediaObject(blogid, username, password, mw.CreateMediaObject(i.ToString()));
}
Post post = new Post();
//post.categories = new string[] { "Test Posts" };
post.title = "Test Title"";
//내용 작성
post.description =  "<img src=" + MO_url[0].url.ToString() + <br mode=" hold=" />                                  "><br>" +
                                  "<img src=" +MO_url[1].url.ToString()+">"+
                             
                                   "<br>" +
                                   "<img src=" + MO_url[2].url.ToString() + ">" +</img></br></img></br></img>
 
Share this answer
 
Comments
hapiten 20-May-16 11:57am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900